[llvm-commits] [llvm] r161002 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/macro-args.s

Jim Grosbach grosbach at apple.com
Mon Jul 30 15:44:17 PDT 2012


Author: grosbach
Date: Mon Jul 30 17:44:17 2012
New Revision: 161002

URL: http://llvm.org/viewvc/llvm-project?rev=161002&view=rev
Log:
Keep empty assembly macro argument values in the middle of the list.

Empty macro arguments at the end of the list should be as-if not specified at
all, but those in the middle of the list need to be kept so as not to screw
up the positional numbering. E.g.:
.macro foo
foo_-bash___:
  nop
.endm

foo 1, 2, 3, 4
foo 1, , 3, 4

Should create two labels, "foo_1_2_3_4" and "foo_1__3_4".

rdar://11948769

Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/test/MC/AsmParser/macro-args.s

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=161002&r1=161001&r2=161002&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Jul 30 17:44:17 2012
@@ -1597,8 +1597,8 @@
     if (ParseMacroArgument(MA))
       return true;
 
-    if (!MA.empty())
-      A.push_back(MA);
+    A.push_back(MA);
+
     if (Lexer.is(AsmToken::EndOfStatement))
       return false;
 
@@ -1619,6 +1619,12 @@
   if (ParseMacroArguments(M, MacroArguments))
     return true;
 
+  // Remove any trailing empty arguments. Do this after-the-fact as we have
+  // to keep empty arguments in the middle of the list or positionality
+  // gets off. e.g.,  "foo 1, , 2" vs. "foo 1, 2,"
+  while (!MacroArguments.empty() && MacroArguments.back().empty())
+    MacroArguments.pop_back();
+
   // Macro instantiation is lexical, unfortunately. We construct a new buffer
   // to hold the macro body with substitutions.
   SmallString<256> Buf;

Modified: llvm/trunk/test/MC/AsmParser/macro-args.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/macro-args.s?rev=161002&r1=161001&r2=161002&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/macro-args.s (original)
+++ llvm/trunk/test/MC/AsmParser/macro-args.s Mon Jul 30 17:44:17 2012
@@ -42,3 +42,15 @@
 // CHECK-NOT: fred
 // CHECK: _bar
 // CHECK-NEXT: fred = 42
+
+
+.macro foo
+foo_$0_$1_$2_$3:
+  nop
+.endm
+
+foo 1, 2, 3, 4
+foo 1, , 3, 4
+
+// CHECK: foo_1_2_3_4:
+// CHECK: foo_1__3_4:





More information about the llvm-commits mailing list