https://github.com/kyulee-com created https://github.com/llvm/llvm-project/pull/243737
When `clang -fthinlto-index=...` cannot load the index, or the ThinLTO backend fails (for example, function importing cannot link a source module), clang prints the error to stderr but exits 0 and writes an empty object. The failure then shows up later, far from its cause, as a link error or as a build system complaining about an empty output. Report both failures as errors, so the compile fails where the problem is. Assisted-by: AI coding agent >From 932669f3a47a20d68d3f1dd6b4c53e0ba36e1b13 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee <[email protected]> Date: Tue, 17 Nov 2026 21:39:00 -0800 Subject: [PATCH] [clang][ThinLTO] Report distributed ThinLTO backend failures as errors When `clang -fthinlto-index=...` cannot load the index, or the ThinLTO backend fails (for example, function importing cannot link a source module), clang prints the error to stderr but exits 0 and writes an empty object. The failure then shows up later, far from its cause, as a link error or as a build system complaining about an empty output. Report both failures as errors, so the compile fails where the problem is. Assisted-by: AI coding agent --- clang/lib/CodeGen/BackendUtil.cpp | 9 +++------ clang/test/CodeGen/thinlto_backend.ll | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 61864100756044..502e4adabbbd61 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1457,9 +1457,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], /*ModuleMap=*/nullptr, Conf.CodeGenOnly, /*BitcodeLibFuncs=*/{}, /*IRAddStream=*/nullptr, CGOpts.CmdArgs)) { - handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { - errs() << "Error running ThinLTO backend: " << EIB.message() << '\n'; - }); + Diags.Report(diag::err_fe_error_backend) << toString(std::move(E)); } } @@ -1568,9 +1566,8 @@ void clang::emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts, CGOpts.ThinLTOIndexFile, /*IgnoreEmptyThinLTOIndexFile*/ true) .moveInto(CombinedIndex)) { - logAllUnhandledErrors(std::move(E), errs(), - "Error loading index file '" + - CGOpts.ThinLTOIndexFile + "': "); + Diags.Report(diag::err_fe_error_reading) + << CGOpts.ThinLTOIndexFile << toString(std::move(E)); return; } diff --git a/clang/test/CodeGen/thinlto_backend.ll b/clang/test/CodeGen/thinlto_backend.ll index 1864fb499f8fe3..e6a8e049ca92d6 100644 --- a/clang/test/CodeGen/thinlto_backend.ll +++ b/clang/test/CodeGen/thinlto_backend.ll @@ -9,8 +9,8 @@ ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' ; Ensure we get expected error for missing index file -; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 -; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc' +; RUN: not %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1 +; CHECK-ERROR1: error: error reading 'bad.thinlto.bc' ; Ensure we ignore empty index file, and run non-ThinLTO compilation which ; would not import f2 @@ -46,8 +46,8 @@ ; Ensure we get expected error for input files without summaries ; RUN: opt -o %t2.o %s -; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR2 -; CHECK-ERROR2: Error loading imported file {{.*}}: Could not find module summary +; RUN: not %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR2 +; CHECK-ERROR2: error in backend: Error loading imported file {{.*}}: Could not find module summary target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
