MC assembly parser handling for trailing comma in macro instantiation.
authorJim Grosbach <grosbach@apple.com>
Mon, 16 Apr 2012 21:18:49 +0000 (21:18 +0000)
committerJim Grosbach <grosbach@apple.com>
Mon, 16 Apr 2012 21:18:49 +0000 (21:18 +0000)
A trailing comma means no argument at all (i.e., as if the comma were not
present), not an empty argument to the invokee.

rdar://11252521

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

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/macro-args.s

index 2d61cac62585b913c189a037fe1859ecf889b7e6..8aef43cb0b4cf9e38d7d0aa24d8714caa5d4e7c6 100644 (file)
@@ -1527,11 +1527,11 @@ bool AsmParser::HandleMacroEntry(StringRef Name, SMLoc NameLoc,
     }
     Lex();
   }
-  // If there weren't any arguments, erase the token vector so everything
-  // else knows that. Leaving around the vestigal empty token list confuses
-  // things.
-  if (MacroArguments.size() == 1 && MacroArguments.back().empty())
-    MacroArguments.clear();
+  // If the last argument didn't end up with any tokens, it's not a real
+  // argument and we should remove it from the list. This happens with either
+  // a tailing comma or an empty argument list.
+  if (MacroArguments.back().empty())
+    MacroArguments.pop_back();
 
   // Macro instantiation is lexical, unfortunately. We construct a new buffer
   // to hold the macro body with substitutions.
index 4b878999e42479b34831c83b3871c4d30e301af2..13b197a55a819c0c26949c3b498717f7e1faf2e7 100644 (file)
@@ -18,3 +18,27 @@ bar
 
 // CHECK: .long 3
 // CHECK: .long 0
+
+
+.macro top
+    middle _$0, $1
+.endm
+.macro middle
+     $0:
+    .if $n > 1
+        bottom $1
+    .endif
+.endm
+.macro bottom
+    .set fred, $0
+.endm
+
+.text
+
+top foo
+top bar, 42
+
+// CHECK: _foo:
+// CHECK-NOT: fred
+// CHECK: _bar
+// CHECK-NEXT: fred = 42