[llvm] r223381 - Fix yet another unseen regression caused by r223113
Asiri Rathnayake
asiri.rathnayake at arm.com
Thu Dec 4 11:34:59 PST 2014
Author: asiri
Date: Thu Dec 4 13:34:59 2014
New Revision: 223381
URL: http://llvm.org/viewvc/llvm-project?rev=223381&view=rev
Log:
Fix yet another unseen regression caused by r223113
r223113 added support for ARM modified immediate assembly syntax. Which
assumes all immediate operands are prefixed with a '#'. This assumption
is wrong as per the ARMARM - which recommends that all '#' characters be
treated optional. The current patch fixes this regression and adds a test
case. A follow-up patch will expand the test coverage to other instructions.
Modified:
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/trunk/test/MC/ARM/basic-arm-instructions.s
llvm/trunk/test/MC/ARM/ldr-pseudo-parse-errors.s
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=223381&r1=223380&r2=223381&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Thu Dec 4 13:34:59 2014
@@ -4418,15 +4418,31 @@ ARMAsmParser::parseModImm(OperandVector
MCAsmLexer &Lexer = getLexer();
int64_t Imm1, Imm2;
- if ((Parser.getTok().isNot(AsmToken::Hash) &&
- Parser.getTok().isNot(AsmToken::Dollar))
- || Lexer.peekTok().is(AsmToken::Colon))
+ SMLoc S = Parser.getTok().getLoc();
+
+ // 1) A mod_imm operand can appear in the place of a register name:
+ // add r0, #mod_imm
+ // add r0, r0, #mod_imm
+ // to correctly handle the latter, we bail out as soon as we see an
+ // identifier.
+ //
+ // 2) Similarly, we do not want to parse into complex operands:
+ // mov r0, #mod_imm
+ // mov r0, :lower16:(_foo)
+ if (Parser.getTok().is(AsmToken::Identifier) ||
+ Parser.getTok().is(AsmToken::Colon))
return MatchOperand_NoMatch;
- SMLoc S = Parser.getTok().getLoc();
+ // Hash (dollar) is optional as per the ARMARM
+ if (Parser.getTok().is(AsmToken::Hash) ||
+ Parser.getTok().is(AsmToken::Dollar)) {
+ // Avoid parsing into complex operands (#:)
+ if (Lexer.peekTok().is(AsmToken::Colon))
+ return MatchOperand_NoMatch;
- // Eat the hash (or dollar)
- Parser.Lex();
+ // Eat the hash (dollar)
+ Parser.Lex();
+ }
SMLoc Sx1, Ex1;
Sx1 = Parser.getTok().getLoc();
@@ -4483,12 +4499,6 @@ ARMAsmParser::parseModImm(OperandVector
return MatchOperand_ParseFail;
}
- if (Lexer.peekTok().isNot(AsmToken::Hash) &&
- Lexer.peekTok().isNot(AsmToken::Dollar)) {
- Error(Lexer.peekTok().getLoc(), "immediate operand expected");
- return MatchOperand_ParseFail;
- }
-
// Eat the comma
Parser.Lex();
@@ -4496,8 +4506,10 @@ ARMAsmParser::parseModImm(OperandVector
SMLoc Sx2, Ex2;
Sx2 = Parser.getTok().getLoc();
- // Eat the hash (or dollar)
- Parser.Lex();
+ // Eat the optional hash (dollar)
+ if (Parser.getTok().is(AsmToken::Hash) ||
+ Parser.getTok().is(AsmToken::Dollar))
+ Parser.Lex();
const MCExpr *Imm2Exp;
if (getParser().parseExpression(Imm2Exp, Ex2)) {
Modified: llvm/trunk/test/MC/ARM/basic-arm-instructions.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/basic-arm-instructions.s?rev=223381&r1=223380&r2=223381&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/basic-arm-instructions.s (original)
+++ llvm/trunk/test/MC/ARM/basic-arm-instructions.s Thu Dec 4 13:34:59 2014
@@ -16,6 +16,9 @@ _func:
@ ADC (immediate)
@------------------------------------------------------------------------------
adc r1, r2, #0xf
+ adc r1, r2, $0xf
+ adc r1, r2, 0xf
+ adc r1, r2, 15
adc r7, r8, #42, #2
adc r7, r8, #-2147483638
adc r7, r8, #40, #2
@@ -34,6 +37,9 @@ _func:
adceq r1, r2, #0xf00
@ CHECK: adc r1, r2, #15 @ encoding: [0x0f,0x10,0xa2,0xe2]
+@ CHECK: adc r1, r2, #15 @ encoding: [0x0f,0x10,0xa2,0xe2]
+@ CHECK: adc r1, r2, #15 @ encoding: [0x0f,0x10,0xa2,0xe2]
+@ CHECK: adc r1, r2, #15 @ encoding: [0x0f,0x10,0xa2,0xe2]
@ CHECK: adc r7, r8, #-2147483638 @ encoding: [0x2a,0x71,0xa8,0xe2]
@ CHECK: adc r7, r8, #-2147483638 @ encoding: [0x2a,0x71,0xa8,0xe2]
@ CHECK: adc r7, r8, #40, #2 @ encoding: [0x28,0x71,0xa8,0xe2]
Modified: llvm/trunk/test/MC/ARM/ldr-pseudo-parse-errors.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/ldr-pseudo-parse-errors.s?rev=223381&r1=223380&r2=223381&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/ldr-pseudo-parse-errors.s (original)
+++ llvm/trunk/test/MC/ARM/ldr-pseudo-parse-errors.s Thu Dec 4 13:34:59 2014
@@ -4,7 +4,7 @@
.text
bar:
mov r0, =0x101
-@ CHECK: error: unexpected token in operand
+@ CHECK: error: unknown token in expression
@ CHECK: mov r0, =0x101
@ CHECK: ^
More information about the llvm-commits
mailing list