mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 23:31:50 +08:00
[clang][codegen] Set CurLinkModule in CodeGenAction::ExecuteAction
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. Reviewed By: xur Differential Revision: https://reviews.llvm.org/D108603
This commit is contained in:
@@ -22,8 +22,9 @@ def note_fe_inline_asm_here : Note<"instantiated into assembly here">;
|
||||
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>;
|
||||
|
||||
@@ -1194,6 +1194,9 @@ def ASM : DiagGroup<"asm", [
|
||||
ASMOperandWidths
|
||||
]>;
|
||||
|
||||
// Linker warnings.
|
||||
def LinkerWarnings : DiagGroup<"linker-warnings">;
|
||||
|
||||
// OpenMP warnings.
|
||||
def SourceUsesOpenMP : DiagGroup<"source-uses-openmp">;
|
||||
def OpenMPClauses : DiagGroup<"openmp-clauses">;
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace clang {
|
||||
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 @@ namespace clang {
|
||||
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 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
|
||||
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 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
|
||||
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 @@ void CodeGenAction::ExecuteAction() {
|
||||
// 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.
|
||||
|
||||
9
clang/test/CodeGen/Inputs/linker-diagnostic1.ll
Normal file
9
clang/test/CodeGen/Inputs/linker-diagnostic1.ll
Normal file
@@ -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
|
||||
}
|
||||
17
clang/test/CodeGen/linker-diagnostic.ll
Normal file
17
clang/test/CodeGen/linker-diagnostic.ll
Normal file
@@ -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
|
||||
}
|
||||
@@ -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 []
|
||||
|
||||
Reference in New Issue
Block a user