[clang] dbd3ade - [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 9 08:29:17 PDT 2022


Author: Joseph Huber
Date: 2022-07-09T11:29:04-04:00
New Revision: dbd3ade17bc1ed889f306ce13955b2048b5df969

URL: https://github.com/llvm/llvm-project/commit/dbd3ade17bc1ed889f306ce13955b2048b5df969
DIFF: https://github.com/llvm/llvm-project/commit/dbd3ade17bc1ed889f306ce13955b2048b5df969.diff

LOG: [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

The LTO pipeline handles its errors using the diagnostics handler
callback function. We were not checking the results of these errors and
not properly returning an error code in the linker wrapper when errors
occured inside of the LTO pipeline. This patch adds a simple boolean
flag to indicate if the LTO backend failed to any reason and quit.

Reviewed By: ye-luo

Differential Revision: https://reviews.llvm.org/D129423

Added: 
    

Modified: 
    clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index f0509b68ee0b3..21a8bfa966626 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@ static std::list<SmallString<128>> TempFiles;
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic<bool> LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@ void diagnosticHandler(const DiagnosticInfo &DI) {
   switch (DI.getSeverity()) {
   case DS_Error:
     WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+    LTOError = true;
     break;
   case DS_Warning:
     WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@ std::unique_ptr<lto::LTO> createLTO(
   if (Conf.OptLevel > 0)
     Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
   if (Error Err = LTOBackend->run(AddStream))
     return Err;
 
+  if (LTOError)
+    return createStringError(inconvertibleErrorCode(),
+                             "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
     if (BitcodeOutput.size() != 1 || !WholeProgram)


        


More information about the cfe-commits mailing list