diff options
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 10 | ||||
-rw-r--r-- | test/MC/AsmParser/macro-args.s | 24 |
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 2d61cac..8aef43c 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -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. diff --git a/test/MC/AsmParser/macro-args.s b/test/MC/AsmParser/macro-args.s index 4b87899..13b197a 100644 --- a/test/MC/AsmParser/macro-args.s +++ b/test/MC/AsmParser/macro-args.s @@ -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 |