From 955365524aeea122243cb8ef201cd2687e7694b4 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 2 Mar 2021 13:41:50 +0100 Subject: [PATCH] [MCParser] Bring back srcmanager diagnostics in AsmParser AsmParser may have no LLVMContext attached to it, which means after 5de2d189e6ad466a1f0616195e8c524a4eb3cbc0 everything goes to stderr. Restore the old behavior. --- llvm/lib/MC/MCParser/AsmParser.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 4a7d82d845df..7a735d9b06d6 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -2370,7 +2370,10 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { // manager changed or buffer changed (like in a nested include) then just // print the normal diagnostic using its Filename and LineNo. if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) { - Parser->getContext().diagnose(Diag); + if (Parser->SavedDiagHandler) + Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext); + else + Parser->getContext().diagnose(Diag); return; } @@ -2389,7 +2392,10 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { Diag.getColumnNo(), Diag.getKind(), Diag.getMessage(), Diag.getLineContents(), Diag.getRanges()); - Parser->getContext().diagnose(NewDiag); + if (Parser->SavedDiagHandler) + Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext); + else + Parser->getContext().diagnose(NewDiag); } // FIXME: This is mostly duplicated from the function in AsmLexer.cpp. The