AsmParser: improve diagnostics for invalid variants
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 26 Jan 2014 22:29:43 +0000 (22:29 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 26 Jan 2014 22:29:43 +0000 (22:29 +0000)
An emitted diagnostic for an invalid relocation variant would place the caret on
the token following the relocation variant indicator or at the end of the line
if there was no following token.  This change corrects the placement of the
caret to point to the token.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200159 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/variant-diagnostics-2.s [new file with mode: 0644]
test/MC/AsmParser/variant-diagnostics.s [new file with mode: 0644]

index dba543b683349d4412fed6ff5193635b5ae1375b..a1d016261f5082e518c1bc984bc44513a7083c73 100644 (file)
@@ -836,7 +836,8 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
         Variant = MCSymbolRefExpr::VK_None;
       } else {
         Variant = MCSymbolRefExpr::VK_None;
-        return TokError("invalid variant '" + Split.second + "'");
+        return Error(SMLoc::getFromPointer(Split.second.begin()),
+                     "invalid variant '" + Split.second + "'");
       }
     }
 
diff --git a/test/MC/AsmParser/variant-diagnostics-2.s b/test/MC/AsmParser/variant-diagnostics-2.s
new file mode 100644 (file)
index 0000000..bf6a7c7
--- /dev/null
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple i386-linux-gnu -filetype asm -o /dev/null 2>&1 %s \
+# RUN:   | FileCheck %s
+
+       .text
+
+function:
+       call external@invalid
+
+# CHECK: error: invalid variant 'invalid'
+# CHECK:       call external@invalid
+# CHECK:                      ^
diff --git a/test/MC/AsmParser/variant-diagnostics.s b/test/MC/AsmParser/variant-diagnostics.s
new file mode 100644 (file)
index 0000000..535ee26
--- /dev/null
@@ -0,0 +1,13 @@
+@ RUN: not llvm-mc -triple armv7-linux-eabi -filetype asm -o /dev/null 2>&1 %s \
+@ RUN:   | FileCheck %s
+
+       .arch armv7
+
+       .type invalid_variant,%function
+invalid_variant:
+       bx target(invalid)
+
+@ CHECK: error: invalid variant 'invalid'
+@ CHECK:       bx target(invalid)
+@ CHECK:                  ^
+