[PATCH] D73176: [ARM] Fix dropped dollar sign from symbols in branch targets

Lucas Prates via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 08:48:31 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf1c2e561e5f: [ARM] Fix dropped dollar sign from symbols in branch targets (authored by pratlucas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73176/new/

https://reviews.llvm.org/D73176

Files:
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/test/MC/ARM/arm-branches.s


Index: llvm/test/MC/ARM/arm-branches.s
===================================================================
--- llvm/test/MC/ARM/arm-branches.s
+++ llvm/test/MC/ARM/arm-branches.s
@@ -13,3 +13,32 @@
 @ CHECK: bl	#4                      @ encoding: [0x01,0x00,0x00,0xeb]
 @ CHECK: beq	#4                      @ encoding: [0x01,0x00,0x00,0x0a]
 @ CHECK: blx	#2                      @ encoding: [0x00,0x00,0x00,0xfb]
+
+ at ------------------------------------------------------------------------------
+@ Leading '$' on branch targets must not be dropped if part of symbol names
+ at ------------------------------------------------------------------------------
+
+        .global $foo
+        b $foo
+        bl $foo
+        beq $foo
+        blx $foo
+        b $foo + 4
+
+@ CHECK: b      ($foo)                      @ encoding: [A,A,A,0xea]
+@ CHECK: bl     ($foo)                      @ encoding: [A,A,A,0xeb]
+@ CHECK: beq    ($foo)                      @ encoding: [A,A,A,0x0a]
+@ CHECK: blx    ($foo)                      @ encoding: [A,A,A,0xfa]
+@ CHECK: b      #($foo)+4                   @ encoding: [A,A,A,0xea]
+
+ at ------------------------------------------------------------------------------
+@ Leading '$' should be allowed to introduce an expression
+ at ------------------------------------------------------------------------------
+
+        .global bar
+        b $ 4
+        bl $ bar + 4
+        blx $ bar
+@ CHECK: b	    #4                        @ encoding: [0x01,0x00,0x00,0xea]
+@ CHECK: bl     #bar+4                    @ encoding: [A,A,A,0xeb]
+@ CHECK: blx    bar                       @ encoding: [A,A,A,0xfa]
Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
===================================================================
--- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -6119,20 +6119,35 @@
   case AsmToken::LCurly:
     return parseRegisterList(Operands, !Mnemonic.startswith("clr"));
   case AsmToken::Dollar:
-  case AsmToken::Hash:
-    // #42 -> immediate.
+  case AsmToken::Hash: {
+    // #42 -> immediate
+    // $ 42 -> immediate
+    // $foo -> symbol name
+    // $42 -> symbol name
     S = Parser.getTok().getLoc();
-    Parser.Lex();
+
+    // Favor the interpretation of $-prefixed operands as symbol names.
+    // Cases where immediates are explicitly expected are handled by their
+    // specific ParseMethod implementations.
+    auto AdjacentToken = getLexer().peekTok(/*ShouldSkipSpace=*/false);
+    bool ExpectIdentifier = Parser.getTok().is(AsmToken::Dollar) &&
+                            (AdjacentToken.is(AsmToken::Identifier) ||
+                             AdjacentToken.is(AsmToken::Integer));
+    if (!ExpectIdentifier) {
+      // Token is not part of identifier. Drop leading $ or # before parsing
+      // expression.
+      Parser.Lex();
+    }
 
     if (Parser.getTok().isNot(AsmToken::Colon)) {
-      bool isNegative = Parser.getTok().is(AsmToken::Minus);
+      bool IsNegative = Parser.getTok().is(AsmToken::Minus);
       const MCExpr *ImmVal;
       if (getParser().parseExpression(ImmVal))
         return true;
       const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
       if (CE) {
         int32_t Val = CE->getValue();
-        if (isNegative && Val == 0)
+        if (IsNegative && Val == 0)
           ImmVal = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
                                           getContext());
       }
@@ -6151,7 +6166,7 @@
     }
     // w/ a ':' after the '#', it's just like a plain ':'.
     LLVM_FALLTHROUGH;
-
+  }
   case AsmToken::Colon: {
     S = Parser.getTok().getLoc();
     // ":lower16:" and ":upper16:" expression prefixes


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73176.248749.patch
Type: text/x-patch
Size: 3735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200306/42bb3cc8/attachment.bin>


More information about the llvm-commits mailing list