Fix macros arguments with an underscore, dot or dollar in them. This is based
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 21 Aug 2012 18:29:30 +0000 (18:29 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 21 Aug 2012 18:29:30 +0000 (18:29 +0000)
on a patch by Andy/PaX. I added the support for dot and dollar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162298 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/macros.s

index f7236627d5df8102b106a350242715133a526de3..240c10b5470348536c12a47d0a826ba3580990db 100644 (file)
@@ -1454,6 +1454,14 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
     NewDiag.print(0, OS);
 }
 
+// FIXME: This is mostly duplicated from the function in AsmLexer.cpp. The
+// difference being that that function accepts '@' as part of identifiers and
+// we can't do that. AsmLexer.cpp should probably be changed to handle
+// '@' as a special case when needed.
+static bool isIdentifierChar(char c) {
+  return isalnum(c) || c == '_' || c == '$' || c == '.';
+}
+
 bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
                             const MacroParameters &Parameters,
                             const MacroArguments &A,
@@ -1518,7 +1526,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
       Pos += 2;
     } else {
       unsigned I = Pos + 1;
-      while (isalnum(Body[I]) && I + 1 != End)
+      while (isIdentifierChar(Body[I]) && I + 1 != End)
         ++I;
 
       const char *Begin = Body.data() + Pos +1;
index 29575929923896a48ff14180adcb13e6c441e609..dd2cc1f14980a241eb6142a929c5d02648499bb6 100644 (file)
@@ -37,3 +37,24 @@ test3 1,2 3
 
 // CHECK: .globl       "ab)(,) -- (cd)"
 test4 a b)(,),(cd)
+
+.macro test5 _a
+.globl "\_a"
+.endm
+
+test5 zed1
+// CHECK: .globl zed1
+
+.macro test6 $a
+.globl "\$a"
+.endm
+
+test6 zed2
+// CHECK: .globl zed2
+
+.macro test7 .a
+.globl "\.a"
+.endm
+
+test7 zed3
+// CHECK: .globl zed3