[PATCH] D68764: [ARM][AsmParser] handles offset expression in parentheses
Jian Cai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 23:52:59 PDT 2019
jcai19 created this revision.
Herald added subscribers: llvm-commits, hiraditya, kristof.beyls.
Herald added a project: LLVM.
jcai19 added a reviewer: nickdesaulniers.
jcai19 added subscribers: manojgupta, llozano.
Integrated assembler does not acceet offset expressions surrounded by
parenthesis. Handle this case for GAS compability.
https://bugs.llvm.org/show_bug.cgi?id=43631
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68764
Files:
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/test/MC/ARM/gas-compl.s
Index: llvm/test/MC/ARM/gas-compl.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ARM/gas-compl.s
@@ -0,0 +1,8 @@
+@ RUN: llvm-mc -triple=arm < %s | FileCheck %s
+
+@ CHECK: ldr r12, [sp, #15]
+.syntax unified
+ ldr r12, [sp, #(15)]
+@ CHECK: ldr r12, [sp, #40]
+.syntax unified
+ ldr r12, [sp, #(15+5*5)]
Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
===================================================================
--- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -5734,19 +5734,24 @@
}
// If we have a '#', it's an immediate offset, else assume it's a register
- // offset. Be friendly and also accept a plain integer (without a leading
- // hash) for gas compatibility.
+ // offset. Be friendly and also accept a plain integer or expression (without
+ // a leading hash) for gas compatibility.
if (Parser.getTok().is(AsmToken::Hash) ||
Parser.getTok().is(AsmToken::Dollar) ||
+ Parser.getTok().is(AsmToken::LParen) ||
Parser.getTok().is(AsmToken::Integer)) {
- if (Parser.getTok().isNot(AsmToken::Integer))
- Parser.Lex(); // Eat '#' or '$'.
+ bool StartsWithParen = false;
+ if (Parser.getTok().isNot(AsmToken::Integer)) {
+ StartsWithParen = Parser.getTok().is(AsmToken::LParen);
+ Parser.Lex(); // Eat '#' or '$' or '('
+ }
E = Parser.getTok().getLoc();
bool isNegative = getParser().getTok().is(AsmToken::Minus);
const MCExpr *Offset;
- if (getParser().parseExpression(Offset))
+ if (getParser().parseExpression(Offset)) {
return true;
+ }
// The expression has to be a constant. Memory references with relocations
// don't come through here, as they use the <label> forms of the relevant
@@ -5762,6 +5767,10 @@
CE = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
getContext());
+ // Check if the offset is surrounded by parentheses
+ if (StartsWithParen && Parser.getTok().isNot(AsmToken::RParen))
+ return Error(Parser.getTok().getLoc(), "')' expected");
+
// Now we should have the closing ']'
if (Parser.getTok().isNot(AsmToken::RBrac))
return Error(Parser.getTok().getLoc(), "']' expected");
@@ -6048,6 +6057,8 @@
S = Parser.getTok().getLoc();
Parser.Lex();
+ llvm::dbgs() << __func__ << Parser.getTok().getString() << "\n";
+
if (Parser.getTok().isNot(AsmToken::Colon)) {
bool isNegative = Parser.getTok().is(AsmToken::Minus);
const MCExpr *ImmVal;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68764.224261.patch
Type: text/x-patch
Size: 2609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/a934a7eb/attachment.bin>
More information about the llvm-commits
mailing list