AsmParser: Disable Darwin-style macro argument expansion on non-darwin targets.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 20 Feb 2014 13:36:32 +0000 (13:36 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 20 Feb 2014 13:36:32 +0000 (13:36 +0000)
There is code in the wild that relies on $0 not being expanded.

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

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/exprs.s
test/MC/AsmParser/macros-gas.s

index f73e56ade2d76fe06b3a7430fc934c09ecd82756..c4dfc75c6d2db89c48aba86c990c9ccc8f848562 100644 (file)
@@ -1730,7 +1730,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
                             ArrayRef<MCAsmMacroParameter> Parameters,
                             ArrayRef<MCAsmMacroArgument> A, const SMLoc &L) {
   unsigned NParameters = Parameters.size();
-  if (NParameters != 0 && NParameters != A.size())
+  if ((!IsDarwin || NParameters != 0) && NParameters != A.size())
     return Error(L, "Wrong number of arguments");
 
   // A macro without parameters is handled differently on Darwin:
@@ -1740,7 +1740,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
     std::size_t End = Body.size(), Pos = 0;
     for (; Pos != End; ++Pos) {
       // Check for a substitution or escape.
-      if (!NParameters) {
+      if (IsDarwin && !NParameters) {
         // This macro has no parameters, look for $0, $1, etc.
         if (Body[Pos] != '$' || Pos + 1 == End)
           continue;
@@ -1763,7 +1763,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
     if (Pos == End)
       break;
 
-    if (!NParameters) {
+    if (IsDarwin && !NParameters) {
       switch (Body[Pos + 1]) {
       // $$ => $
       case '$':
index a7e10020b67beff6b668a6498a4a84b549a23c3f..c5fc9b594a0c608db95a30625f5a54ceb69891e3 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: llvm-mc -triple i386-unknown-unknown %s > %t
+// RUN: llvm-mc -triple i386-apple-darwin %s
 
 .macro check_expr
   .if ($0) != ($1)
index 6c75363b5e3e82dbfbb3f18f00a4083f932004d1..d907a2517f8c3df4d6e7dcb9c3c246922af280e1 100644 (file)
@@ -91,3 +91,15 @@ test8 1,2 3
 
 // CHECK: .ascii "1,2,3"
 test8 1 2, 3
+
+.macro test10
+.ascii "$20"
+.endm
+
+test10
+// CHECK: .ascii "$20"
+
+test10 42
+// CHECK-ERRORS: 102:10: error: Wrong number of arguments
+// CHECK-ERRORS-NEXT: test10 42
+// CHECK-ERRORS-NEXT: ^