diff --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp --- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp +++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp @@ -118,9 +118,7 @@ addDirectiveHandler<&COFFMasmParser::IgnoreDirective>("title"); // Macro directives - // exitm // goto - // purge // Miscellaneous directives addDirectiveHandler<&COFFMasmParser::ParseDirectiveAlias>("alias"); @@ -153,9 +151,6 @@ addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".mmx"); addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".xmm"); - // Repeat blocks directives - // goto - // Scope directives // comm // externdef diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -734,7 +734,7 @@ DK_MACRO, DK_EXITM, DK_ENDM, - DK_PURGEM, + DK_PURGE, DK_ERR, DK_ERRB, DK_ERRNB, @@ -2311,7 +2311,7 @@ case DK_ENDM: Info.ExitValue = ""; return parseDirectiveEndMacro(IDVal); - case DK_PURGEM: + case DK_PURGE: return parseDirectivePurgeMacro(IDLoc); case DK_END: return parseDirectiveEnd(IDLoc); @@ -5544,23 +5544,27 @@ } /// parseDirectivePurgeMacro -/// ::= .purgem +/// ::= purge identifier ( , identifier )* bool MasmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) { StringRef Name; - SMLoc Loc; - if (parseTokenLoc(Loc) || - check(parseIdentifier(Name), Loc, - "expected identifier in '.purgem' directive") || - parseToken(AsmToken::EndOfStatement, - "unexpected token in '.purgem' directive")) - return true; + while (true) { + SMLoc NameLoc; + if (parseTokenLoc(NameLoc) || + check(parseIdentifier(Name), NameLoc, + "expected identifier in 'purge' directive")) + return true; - if (!getContext().lookupMacro(Name)) - return Error(DirectiveLoc, "macro '" + Name + "' is not defined"); + DEBUG_WITH_TYPE("asm-macros", dbgs() + << "Un-defining macro: " << Name << "\n"); + if (!getContext().lookupMacro(Name)) + return Error(NameLoc, "macro '" + Name + "' is not defined"); + getContext().undefineMacro(Name); + + if (!parseOptionalToken(AsmToken::Comma)) + break; + parseOptionalToken(AsmToken::EndOfStatement); + } - getContext().undefineMacro(Name); - DEBUG_WITH_TYPE("asm-macros", dbgs() - << "Un-defining macro: " << Name << "\n"); return false; } @@ -6322,7 +6326,7 @@ DirectiveKindMap["macro"] = DK_MACRO; DirectiveKindMap["exitm"] = DK_EXITM; DirectiveKindMap["endm"] = DK_ENDM; - // DirectiveKindMap[".purgem"] = DK_PURGEM; + DirectiveKindMap["purge"] = DK_PURGE; DirectiveKindMap[".err"] = DK_ERR; DirectiveKindMap[".errb"] = DK_ERRB; DirectiveKindMap[".errnb"] = DK_ERRNB; diff --git a/llvm/test/tools/llvm-ml/macro.test b/llvm/test/tools/llvm-ml/macro.test --- a/llvm/test/tools/llvm-ml/macro.test +++ b/llvm/test/tools/llvm-ml/macro.test @@ -134,4 +134,23 @@ ; CHECK-NEXT: jmp "??0001" local_symbol_test ENDP +PURGE ambiguous_substitution_macro, local_symbol_macro, + optional_parameter_macro + +; Redefinition +local_symbol_macro MACRO + LOCAL b +b: xor eax, eax + jmp b +ENDM + +purge_test PROC +; CHECK-LABEL: purge_test: + + local_symbol_macro +; CHECK: "??0002": +; CHECK-NEXT: xor eax, eax +; CHECK-NEXT: jmp "??0002" +purge_test ENDP + END