[PATCH] D75111: [MC] Allowing the use of $-prefixed integer as asm identifiers

Lucas Prates via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 05:09:50 PST 2020


pratlucas created this revision.
Herald added subscribers: llvm-commits, atanasyan, jrtc27, hiraditya, sdardis.
Herald added a project: LLVM.

Dollar signed prefixed integers were not allowed by the AsmParser to be
used as Identifiers, differing from the GNU assembler behavior.

This patch updates the parsing of Identifiers to consider such cases as
valid, where the identifier string includes the $ prefix itself. As the
Lexer currently splits these occurrences into separate tokens, those
need to be combined by the AsmParser itself.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75111

Files:
  llvm/include/llvm/MC/MCAsmMacro.h
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/ARM/arm-branches.s
  llvm/test/MC/MachO/bad-dollar.s
  llvm/test/MC/MachO/dollar-identifier.s
  llvm/test/MC/Mips/cpsetup-bad.s
  llvm/test/MC/Mips/invalid-instructions-spellcheck.s


Index: llvm/test/MC/Mips/invalid-instructions-spellcheck.s
===================================================================
--- llvm/test/MC/Mips/invalid-instructions-spellcheck.s
+++ llvm/test/MC/Mips/invalid-instructions-spellcheck.s
@@ -13,7 +13,7 @@
 
 $2, $1, $25
 
-# ALL:      error: unexpected token at start of statement
+# ALL:      error: unknown instruction
 # ALL-NEXT: $2, $1, $25
 # ALL-NEXT:  ^
 
Index: llvm/test/MC/Mips/cpsetup-bad.s
===================================================================
--- llvm/test/MC/Mips/cpsetup-bad.s
+++ llvm/test/MC/Mips/cpsetup-bad.s
@@ -12,8 +12,6 @@
 # ASM: :[[@LINE-1]]:23: error: expected save register or stack offset
         .cpsetup $31, $32, __cerror
 # ASM: :[[@LINE-1]]:23: error: invalid register
-        .cpsetup $25, $2, $3
-# ASM: :[[@LINE-1]]:27: error: expected expression
         .cpsetup $25, $2, 4
 # ASM: :[[@LINE-1]]:28: error: expected symbol
         .cpsetup $25, $2, 4+65
Index: llvm/test/MC/MachO/dollar-identifier.s
===================================================================
--- /dev/null
+++ llvm/test/MC/MachO/dollar-identifier.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-apple-darwin10 %s | FileCheck %s
+
+.long $1
+// CHECK: .long ($1)
Index: llvm/test/MC/MachO/bad-dollar.s
===================================================================
--- llvm/test/MC/MachO/bad-dollar.s
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s 2> %t.err > %t
-// RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
-
-.long $1
-// CHECK-ERROR: 4:7: error: invalid token in expression
Index: llvm/test/MC/ARM/arm-branches.s
===================================================================
--- llvm/test/MC/ARM/arm-branches.s
+++ llvm/test/MC/ARM/arm-branches.s
@@ -19,17 +19,22 @@
 @------------------------------------------------------------------------------
 
         .global $foo
+        .global $4
         b $foo
         bl $foo
         beq $foo
         blx $foo
         b $foo + 4
+        bl $4
+        beq $4 + 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]
+@ CHECK: bl     ($4)                        @ encoding: [A,A,A,0xeb]
+@ CHECK: beq    #($4)+4                     @ encoding: [A,A,A,0x0a]
 
 @------------------------------------------------------------------------------
 @ Leading '$' should be allowed to introduce an expression
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -2855,7 +2855,8 @@
     AsmToken Buf[1];
     Lexer.peekTokens(Buf, false);
 
-    if (Buf[0].isNot(AsmToken::Identifier))
+    if (Buf[0].isNot(AsmToken::Identifier) && Buf[0].isNot(AsmToken::String)
+        && Buf[0].isNot(AsmToken::Integer))
       return true;
 
     // We have a '$' or '@' followed by an identifier, make sure they are adjacent.
Index: llvm/include/llvm/MC/MCAsmMacro.h
===================================================================
--- llvm/include/llvm/MC/MCAsmMacro.h
+++ llvm/include/llvm/MC/MCAsmMacro.h
@@ -97,7 +97,7 @@
   /// be used as the identifier, e.g., it does not include the quotes on
   /// strings.
   StringRef getIdentifier() const {
-    if (Kind == Identifier)
+    if (Kind == Identifier || Kind == Integer)
       return getString();
     return getStringContents();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75111.246419.patch
Type: text/x-patch
Size: 3715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200225/3879aae4/attachment.bin>


More information about the llvm-commits mailing list