diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -1066,21 +1066,11 @@ PP.EnterToken(Crasher, /*IsReinject*/ false); } } else if (II->isStr("dump")) { - Token Identifier; - PP.LexUnexpandedToken(Identifier); - if (auto *DumpII = Identifier.getIdentifierInfo()) { - Token DumpAnnot; - DumpAnnot.startToken(); - DumpAnnot.setKind(tok::annot_pragma_dump); - DumpAnnot.setAnnotationRange( - SourceRange(Tok.getLocation(), Identifier.getLocation())); - DumpAnnot.setAnnotationValue(DumpII); - PP.DiscardUntilEndOfDirective(); - PP.EnterToken(DumpAnnot, /*IsReinject*/false); - } else { - PP.Diag(Identifier, diag::warn_pragma_debug_missing_argument) - << II->getName(); - } + Token DumpAnnot; + DumpAnnot.startToken(); + DumpAnnot.setKind(tok::annot_pragma_dump); + DumpAnnot.setAnnotationRange(SourceRange(Tok.getLocation())); + PP.EnterToken(DumpAnnot, /*IsReinject*/false); } else if (II->isStr("diag_mapping")) { Token DiagName; PP.LexUnexpandedToken(DiagName); diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ASTContext.h" #include "clang/Basic/PragmaKinds.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/Token.h" #include "clang/Parse/LoopHint.h" @@ -706,10 +707,27 @@ void Parser::HandlePragmaDump() { assert(Tok.is(tok::annot_pragma_dump)); - IdentifierInfo *II = - reinterpret_cast(Tok.getAnnotationValue()); - Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II); ConsumeAnnotationToken(); + if (Tok.is(tok::eod)) { + PP.Diag(Tok, diag::warn_pragma_debug_missing_argument) << "dump"; + } else if (NextToken().is(tok::eod)) { + if (Tok.isNot(tok::identifier)) { + PP.Diag(Tok, diag::warn_pragma_debug_unexpected_argument); + ConsumeAnyToken(); + ExpectAndConsume(tok::eod); + return; + } + IdentifierInfo *II = Tok.getIdentifierInfo(); + Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II); + ConsumeToken(); + } else { + ExprResult E = ParseExpression(); + if (!E.isInvalid()) { + E.get()->dump(); + } + SkipUntil(tok::eod, StopBeforeMatch); + } + ExpectAndConsume(tok::eod); } void Parser::HandlePragmaWeak() {