[llvm] r177463 - Fix pr13145 - Naming a function like a register name confuses the asm parser.
Chad Rosier
mcrosier at apple.com
Tue Mar 19 16:44:03 PDT 2013
Author: mcrosier
Date: Tue Mar 19 18:44:03 2013
New Revision: 177463
URL: http://llvm.org/viewvc/llvm-project?rev=177463&view=rev
Log:
Fix pr13145 - Naming a function like a register name confuses the asm parser.
Patch by Stepan Dyatkovskiy <stpworld at narod.ru>
rdar://13457826
Added:
llvm/trunk/test/MC/ARM/2013-03-18-Br-to-label-named-like-reg.s
Modified:
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
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=177463&r1=177462&r2=177463&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Mar 19 18:44:03 2013
@@ -4593,20 +4593,26 @@ bool ARMAsmParser::parseOperand(SmallVec
Error(Parser.getTok().getLoc(), "unexpected token in operand");
return true;
case AsmToken::Identifier: {
- if (!tryParseRegisterWithWriteBack(Operands))
- return false;
- int Res = tryParseShiftRegister(Operands);
- if (Res == 0) // success
- return false;
- else if (Res == -1) // irrecoverable error
- return true;
- // If this is VMRS, check for the apsr_nzcv operand.
- if (Mnemonic == "vmrs" &&
- Parser.getTok().getString().equals_lower("apsr_nzcv")) {
- S = Parser.getTok().getLoc();
- Parser.Lex();
- Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
- return false;
+ // If we've seen a branch mnemonic, the next operand must be a label. This
+ // is true even if the label is a register name. So "br r1" means branch to
+ // label "r1".
+ bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
+ if (!ExpectLabel) {
+ if (!tryParseRegisterWithWriteBack(Operands))
+ return false;
+ int Res = tryParseShiftRegister(Operands);
+ if (Res == 0) // success
+ return false;
+ else if (Res == -1) // irrecoverable error
+ return true;
+ // If this is VMRS, check for the apsr_nzcv operand.
+ if (Mnemonic == "vmrs" &&
+ Parser.getTok().getString().equals_lower("apsr_nzcv")) {
+ S = Parser.getTok().getLoc();
+ Parser.Lex();
+ Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
+ return false;
+ }
}
// Fall though for the Identifier case that is not a register or a
Added: llvm/trunk/test/MC/ARM/2013-03-18-Br-to-label-named-like-reg.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/2013-03-18-Br-to-label-named-like-reg.s?rev=177463&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/2013-03-18-Br-to-label-named-like-reg.s (added)
+++ llvm/trunk/test/MC/ARM/2013-03-18-Br-to-label-named-like-reg.s Tue Mar 19 18:44:03 2013
@@ -0,0 +1,5 @@
+@ RUN: llvm-mc -arch arm %s
+@ CHECK: test:
+@ CHECK: br r1
+test:
+ bl r1
More information about the llvm-commits
mailing list