From f6ca37bf1809b2fa8f6615d4a30eadf8f479c700 Mon Sep 17 00:00:00 2001 From: paperchalice Date: Sat, 13 Apr 2024 18:45:37 +0800 Subject: [NewPM] Set diagnostic handler in `MachineModuleAnalysis` (#88229) `setDiagnosticHandler` is idempotent. --- llvm/lib/CodeGen/MachineModuleInfo.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'llvm/lib/CodeGen/MachineModuleInfo.cpp') diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index f24288b..1dba591 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -213,7 +213,6 @@ static unsigned getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr, bool MachineModuleInfoWrapperPass::doInitialization(Module &M) { MMI.initialize(); MMI.TheModule = &M; - // FIXME: Do this for new pass manager. LLVMContext &Ctx = M.getContext(); MMI.getContext().setDiagnosticHandler( [&Ctx, &M](const SMDiagnostic &SMD, bool IsInlineAsm, @@ -240,6 +239,17 @@ AnalysisKey MachineModuleAnalysis::Key; MachineModuleAnalysis::Result MachineModuleAnalysis::run(Module &M, ModuleAnalysisManager &) { MMI.TheModule = &M; + LLVMContext &Ctx = M.getContext(); + MMI.getContext().setDiagnosticHandler( + [&Ctx, &M](const SMDiagnostic &SMD, bool IsInlineAsm, + const SourceMgr &SrcMgr, + std::vector &LocInfos) { + unsigned LocCookie = 0; + if (IsInlineAsm) + LocCookie = getLocCookie(SMD, SrcMgr, LocInfos); + Ctx.diagnose( + DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie)); + }); MMI.DbgInfoAvailable = !DisableDebugInfoPrinting && !M.debug_compile_units().empty(); return Result(MMI); -- cgit v1.1