inglorion created this revision. inglorion requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
CodeGenAction::ExecuteAction creates a BackendConsumer for the purpose of handling diagnostics. The BackendConsumer's DiagnosticHandlerImpl method expects CurLinkModule to be set, but this did not happen on the code path that goes through ExecuteAction. This change makes it so that the BackendConsumer constructor used by ExecuteAction requires the Module to be specified and passes the appropriate module in ExecuteAction. The change also adds a test that fails without this change and passes with it. To make the test work, the FIXME in the handling of DK_Linker diagnostics was addressed so that warnings and notes are no longer silently discarded. Since this introduces a new warning diagnostic, a flag to control it (-Wlinker-warnings) has also been added. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108603 Files: clang/include/clang/Basic/DiagnosticFrontendKinds.td clang/include/clang/Basic/DiagnosticGroups.td clang/lib/CodeGen/CodeGenAction.cpp clang/test/CodeGen/Inputs/linker-diagnostic1.ll clang/test/CodeGen/linker-diagnostic.ll clang/test/Misc/serialized-diags-driver.c
Index: clang/test/Misc/serialized-diags-driver.c =================================================================== --- clang/test/Misc/serialized-diags-driver.c +++ clang/test/Misc/serialized-diags-driver.c @@ -8,7 +8,8 @@ // RUN: %clang -Wx-typoed-warning -Wall -fsyntax-only --serialize-diagnostics %t.diag %s // RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s -// CHECK: warning: unknown warning option '-Wx-typoed-warning' [-Wunknown-warning-option] [] +// CHECK: warning: unknown warning option '-Wx-typoed-warning' +// CHECK-SAME: [-Wunknown-warning-option] [] // CHECK: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] // CHECK: note: initialize the variable 'voodoo' to silence this warning [] Index: clang/test/CodeGen/linker-diagnostic.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/linker-diagnostic.ll @@ -0,0 +1,17 @@ +; RUN: mkdir -p %t +; RUN: opt -module-summary -o %t/foo.o %s +; RUN: opt -module-summary -o %t/bar.o %S/Inputs/linker-diagnostic1.ll +; RUN: llvm-lto2 run --thinlto-distributed-indexes -r %t/foo.o,foo,plx -r %t/bar.o,bar,plx \ +; RUN: -r %t/bar.o,foo, -o %t/foobar.so %t/foo.o %t/bar.o +; RUN: %clang -c -o %t/lto.bar.o --target=armv4-none-unknown-eabi -O2 \ +; RUN: -fthinlto-index=%t/bar.o.thinlto.bc %t/bar.o -Wno-override-module 2>&1 | FileCheck %s + +; CHECK: linking module '{{.*}}/bar.o': Linking two modules of different target triples: '{{.*}}/foo.o' is 'thumbv6-unknown-linux-gnueabihf' whereas '{{.*}}/bar.o' is 'armv4-none-unknown-eabi' + +target triple = "thumbv6-unknown-linux-gnueabihf" +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + +define i32 @foo(i32 %x) { + %1 = add i32 %x, 1 + ret i32 %1 +} Index: clang/test/CodeGen/Inputs/linker-diagnostic1.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/Inputs/linker-diagnostic1.ll @@ -0,0 +1,9 @@ +target triple = "armv4-none-unknown-eabi" +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + +declare i32 @foo(i32) + +define i32 @bar(i32 %x) { + %1 = tail call i32 @foo(i32 %x) + ret i32 %1 +} Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -160,7 +160,7 @@ const PreprocessorOptions &PPOpts, const CodeGenOptions &CodeGenOpts, const TargetOptions &TargetOpts, - const LangOptions &LangOpts, + const LangOptions &LangOpts, llvm::Module *Module, SmallVector<LinkModule, 4> LinkModules, LLVMContext &C, CoverageSourceInfo *CoverageInfo = nullptr) : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts), @@ -170,7 +170,7 @@ LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, "", HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)), - LinkModules(std::move(LinkModules)) { + LinkModules(std::move(LinkModules)), CurLinkModule(Module) { TimerIsEnabled = CodeGenOpts.TimePasses; llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses; llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun; @@ -779,11 +779,7 @@ ComputeDiagID(Severity, backend_frame_larger_than, DiagID); break; case DK_Linker: - assert(CurLinkModule); - // FIXME: stop eating the warnings and notes. - if (Severity != DS_Error) - return; - DiagID = diag::err_fe_cannot_link_module; + ComputeDiagID(Severity, linking_module, DiagID); break; case llvm::DK_OptimizationRemark: // Optimization remarks are always handled completely by this @@ -845,9 +841,9 @@ DI.print(DP); } - if (DiagID == diag::err_fe_cannot_link_module) { - Diags.Report(diag::err_fe_cannot_link_module) - << CurLinkModule->getModuleIdentifier() << MsgStorage; + if (DI.getKind() == DK_Linker) { + assert(CurLinkModule && "CurLinkModule must be set for linker diagnostics"); + Diags.Report(DiagID) << CurLinkModule->getModuleIdentifier() << MsgStorage; return; } @@ -1088,7 +1084,7 @@ // BackendConsumer. BackendConsumer Result(BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(), - CI.getTargetOpts(), CI.getLangOpts(), + CI.getTargetOpts(), CI.getLangOpts(), TheModule.get(), std::move(LinkModules), *VMContext, nullptr); // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be // true here because the valued names are needed for reading textual IR. Index: clang/include/clang/Basic/DiagnosticGroups.td =================================================================== --- clang/include/clang/Basic/DiagnosticGroups.td +++ clang/include/clang/Basic/DiagnosticGroups.td @@ -1188,6 +1188,9 @@ ASMOperandWidths ]>; +// Linker warnings. +def LinkerWarnings : DiagGroup<"linker-warnings">; + // OpenMP warnings. def SourceUsesOpenMP : DiagGroup<"source-uses-openmp">; def OpenMPClauses : DiagGroup<"openmp-clauses">; Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -22,8 +22,9 @@ def err_fe_source_mgr : Error<"%0">, CatSourceMgr; def warn_fe_source_mgr : Warning<"%0">, CatSourceMgr, InGroup<BackendSourceMgr>; def note_fe_source_mgr : Note<"%0">, CatSourceMgr; -def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">, - DefaultFatal; +def err_fe_linking_module : Error<"cannot link module '%0': %1">, DefaultFatal; +def warn_fe_linking_module : Warning<"linking module '%0': %1">, InGroup<LinkerWarnings>; +def note_fe_linking_module : Note<"linking module '%0': %1">; def warn_fe_frame_larger_than : Warning<"stack frame size (%0) exceeds limit (%1) in %q2">, BackendInfo, InGroup<BackendFrameLargerThan>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits