Skip to content

Commit 55114fd

Browse files
committed
[ARM, Asm] Use correct source location for register tokens
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 llvm-svn: 314799
1 parent 055192c commit 55114fd

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,13 +3407,13 @@ int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
34073407
/// parse for a specific register type.
34083408
bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
34093409
MCAsmParser &Parser = getParser();
3410-
const AsmToken &RegTok = Parser.getTok();
3410+
SMLoc RegStartLoc = Parser.getTok().getLoc();
3411+
SMLoc RegEndLoc = Parser.getTok().getEndLoc();
34113412
int RegNo = tryParseRegister();
34123413
if (RegNo == -1)
34133414
return true;
34143415

3415-
Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3416-
RegTok.getEndLoc()));
3416+
Operands.push_back(ARMOperand::CreateReg(RegNo, RegStartLoc, RegEndLoc));
34173417

34183418
const AsmToken &ExclaimTok = Parser.getTok();
34193419
if (ExclaimTok.is(AsmToken::Exclaim)) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not llvm-mc -triple armv6m--none-eabi < %s 2>&1 | FileCheck %s
2+
3+
// Some of these CHECK lines need to uses regexes to that the amount of
4+
// whitespace between the start of the line and the caret is significant.
5+
6+
add sp, r0, #4
7+
// CHECK: error: invalid instruction, any one of the following would fix this:
8+
// CHECK: note: instruction requires: thumb2
9+
// CHECK: note: invalid operand for instruction
10+
// CHECK-NEXT: {{^ add sp, r0, #4}}
11+
// CHECK-NEXT: {{^ \^}}
12+
// CHECK: note: too many operands for instruction

0 commit comments

Comments
 (0)