From 33b38339a0961c04ce32a6656aa54293d5ca4790 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 28 Jan 2022 11:32:42 -0800 Subject: [lld] Add module name to LTO inline asm diagnostic Close #52781: for LTO, the inline asm diagnostic uses `` as the file name (lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp) and it is unclear which module has the issue. With this patch, we will see the module name (say `asm.o`) before `` with ThinLTO. ``` % clang -flto=thin -c asm.c && myld.lld asm.o -e f ld.lld: error: asm.o :1:2: invalid instruction mnemonic 'invalid' invalid ^~~~~~~ ``` For regular LTO, unfortunately the original module name is lost and we only get ld-temp.o. Reviewed By: #lld-macho, ychen, Jez Ng Differential Revision: https://reviews.llvm.org/D118434 --- llvm/lib/CodeGen/MachineModuleInfo.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/MachineModuleInfo.cpp') diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index 50cbb14e..31d4fc7 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -400,12 +400,14 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) { // FIXME: Do this for new pass manager. LLVMContext &Ctx = M.getContext(); MMI.getContext().setDiagnosticHandler( - [&Ctx](const SMDiagnostic &SMD, bool IsInlineAsm, const SourceMgr &SrcMgr, - std::vector &LocInfos) { + [&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, IsInlineAsm, LocCookie)); + Ctx.diagnose( + DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie)); }); MMI.DbgInfoAvailable = !M.debug_compile_units().empty(); return false; -- cgit v1.1