OSDN Git Service

[ARM, Asm] Use correct source location for register tokens
authorOliver Stannard <oliver.stannard@arm.com>
Tue, 3 Oct 2017 14:30:58 +0000 (14:30 +0000)
committerOliver Stannard <oliver.stannard@arm.com>
Tue, 3 Oct 2017 14:30:58 +0000 (14:30 +0000)
tryParseRegister advances the lexer, so we need to take copies of the start and
end locations of the register operand before calling it.

Previously, the caret in the diagnostic pointer to the comma after the r0
operand in the test, rather than the start of the operand.

Differential revision: https://reviews.llvm.org/D31537

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

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/register-token-source-loc.s [new file with mode: 0644]

index 2ea3096..ad6d64d 100644 (file)
@@ -3407,13 +3407,13 @@ int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
 /// parse for a specific register type.
 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
   MCAsmParser &Parser = getParser();
-  const AsmToken &RegTok = Parser.getTok();
+  SMLoc RegStartLoc = Parser.getTok().getLoc();
+  SMLoc RegEndLoc = Parser.getTok().getEndLoc();
   int RegNo = tryParseRegister();
   if (RegNo == -1)
     return true;
 
-  Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
-                                           RegTok.getEndLoc()));
+  Operands.push_back(ARMOperand::CreateReg(RegNo, RegStartLoc, RegEndLoc));
 
   const AsmToken &ExclaimTok = Parser.getTok();
   if (ExclaimTok.is(AsmToken::Exclaim)) {
diff --git a/test/MC/ARM/register-token-source-loc.s b/test/MC/ARM/register-token-source-loc.s
new file mode 100644 (file)
index 0000000..3907dc1
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: not llvm-mc -triple armv6m--none-eabi < %s 2>&1 | FileCheck %s
+
+// Some of these CHECK lines need to uses regexes to that the amount of
+// whitespace between the start of the line and the caret is significant.
+
+  add sp, r0, #4
+// CHECK: error: invalid instruction, any one of the following would fix this:
+// CHECK: note: instruction requires: thumb2
+// CHECK: note: invalid operand for instruction
+// CHECK-NEXT: {{^  add sp, r0, #4}}
+// CHECK-NEXT: {{^          \^}}
+// CHECK: note: too many operands for instruction