Skip to content

Conversation

@bd1976bris
Copy link
Collaborator

Usage errors in LTOBackend.cpp were previously, misleadingly, reported as internal crashes.

This PR updates LTOBackend.cpp to use reportFatalUsageError for reporting usage-related issues.

LLVM Issue: #140953
Internal Tracker: TOOLCHAIN-17744

Usage errors in `LTOBackend.cpp` were previously, misleadingly,
reported as internal crashes.

This patch updates `LTOBackend.cpp` to use
`reportFatalUsageError` for reporting usage-related issues.

LLVM Issue: llvm#140953
Internal Tracker: TOOLCHAIN-17744
@llvmbot llvmbot added lld lld:ELF lld:COFF LTO Link time optimization (regular/full LTO or ThinLTO) labels May 21, 2025
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-lto

Author: bd1976bris (bd1976bris)

Changes

Usage errors in LTOBackend.cpp were previously, misleadingly, reported as internal crashes.

This PR updates LTOBackend.cpp to use reportFatalUsageError for reporting usage-related issues.

LLVM Issue: #140953
Internal Tracker: TOOLCHAIN-17744


Full diff: https://github.com/llvm/llvm-project/pull/140955.diff

4 Files Affected:

  • (modified) lld/test/COFF/lto-cache-errors.ll (+2-2)
  • (modified) lld/test/ELF/lto/ltopasses-custom.ll (+2-2)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+5-5)
  • (modified) llvm/test/tools/llvm-lto2/X86/pipeline.ll (+2-2)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index a46190a81b623..44719e239d989 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -7,8 +7,8 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; RUN: chmod 444 %t.cache
 
-;; Check emit warnings when we can't create the cache dir
-; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+;; Check fatal usage error emitted when the cache dir can't be created.
+; RUN: not lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
 ; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
 
 target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/lld/test/ELF/lto/ltopasses-custom.ll b/lld/test/ELF/lto/ltopasses-custom.ll
index e37083ca8b8c7..da4a2d517f8e8 100644
--- a/lld/test/ELF/lto/ltopasses-custom.ll
+++ b/lld/test/ELF/lto/ltopasses-custom.ll
@@ -24,13 +24,13 @@ define void @barrier() {
 ; ATOMIC-NEXT: ret void
 
 ; Check that invalid passes are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=iamnotapass -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALID
 ; INVALID: unable to parse pass pipeline description 'iamnotapass': unknown pass name 'iamnotapass'
 
 ; Check that invalid AA pipelines are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=globaldce --lto-aa-pipeline=patatino \
 ; RUN:   -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALIDAA
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index b7db70b99bcbc..abda0147fe233 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -290,7 +290,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.AAPipeline.empty()) {
     AAManager AA;
     if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
-      report_fatal_error(Twine("unable to parse AA pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse AA pipeline description '") +
                          Conf.AAPipeline + "': " + toString(std::move(Err)));
     }
     // Register the AA manager first so that our version is the one used.
@@ -331,7 +331,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   // Parse a custom pipeline if asked to.
   if (!Conf.OptPipeline.empty()) {
     if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
-      report_fatal_error(Twine("unable to parse pass pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse pass pipeline description '") +
                          Conf.OptPipeline + "': " + toString(std::move(Err)));
     }
   } else if (IsThinLTO) {
@@ -415,7 +415,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
   if (!Conf.DwoDir.empty()) {
     std::error_code EC;
     if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
-      report_fatal_error(Twine("Failed to create directory ") + Conf.DwoDir +
+      reportFatalUsageError(Twine("Failed to create directory ") + Conf.DwoDir +
                          ": " + EC.message());
 
     DwoFile = Conf.DwoDir;
@@ -428,14 +428,14 @@ static void codegen(const Config &Conf, TargetMachine *TM,
     std::error_code EC;
     DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
     if (EC)
-      report_fatal_error(Twine("Failed to open ") + DwoFile + ": " +
+      reportFatalUsageError(Twine("Failed to open ") + DwoFile + ": " +
                          EC.message());
   }
 
   Expected<std::unique_ptr<CachedFileStream>> StreamOrErr =
       AddStream(Task, Mod.getModuleIdentifier());
   if (Error Err = StreamOrErr.takeError())
-    report_fatal_error(std::move(Err));
+    reportFatalUsageError(std::move(Err));
   std::unique_ptr<CachedFileStream> &Stream = *StreamOrErr;
   TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;
 
diff --git a/llvm/test/tools/llvm-lto2/X86/pipeline.ll b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
index 93f30d0ee61bc..9416ac5fd9fff 100644
--- a/llvm/test/tools/llvm-lto2/X86/pipeline.ll
+++ b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
@@ -28,13 +28,13 @@ define void @patatino() {
 ; CUSTOM-NEXT: }
 
 ; Check that invalid pipelines are caught as errors.
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -opt-pipeline foogoo 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=ERR
 
 ; ERR: LLVM ERROR: unable to parse pass pipeline description 'foogoo': unknown pass name 'foogoo'
 
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -aa-pipeline patatino \
 ; RUN:  -opt-pipeline lower-atomic 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=AAERR

@bd1976bris bd1976bris requested a review from tru May 21, 2025 19:20
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-lld-coff

Author: bd1976bris (bd1976bris)

Changes

Usage errors in LTOBackend.cpp were previously, misleadingly, reported as internal crashes.

This PR updates LTOBackend.cpp to use reportFatalUsageError for reporting usage-related issues.

LLVM Issue: #140953
Internal Tracker: TOOLCHAIN-17744


Full diff: https://github.com/llvm/llvm-project/pull/140955.diff

4 Files Affected:

  • (modified) lld/test/COFF/lto-cache-errors.ll (+2-2)
  • (modified) lld/test/ELF/lto/ltopasses-custom.ll (+2-2)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+5-5)
  • (modified) llvm/test/tools/llvm-lto2/X86/pipeline.ll (+2-2)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index a46190a81b623..44719e239d989 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -7,8 +7,8 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; RUN: chmod 444 %t.cache
 
-;; Check emit warnings when we can't create the cache dir
-; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+;; Check fatal usage error emitted when the cache dir can't be created.
+; RUN: not lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
 ; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
 
 target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/lld/test/ELF/lto/ltopasses-custom.ll b/lld/test/ELF/lto/ltopasses-custom.ll
index e37083ca8b8c7..da4a2d517f8e8 100644
--- a/lld/test/ELF/lto/ltopasses-custom.ll
+++ b/lld/test/ELF/lto/ltopasses-custom.ll
@@ -24,13 +24,13 @@ define void @barrier() {
 ; ATOMIC-NEXT: ret void
 
 ; Check that invalid passes are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=iamnotapass -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALID
 ; INVALID: unable to parse pass pipeline description 'iamnotapass': unknown pass name 'iamnotapass'
 
 ; Check that invalid AA pipelines are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=globaldce --lto-aa-pipeline=patatino \
 ; RUN:   -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALIDAA
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index b7db70b99bcbc..abda0147fe233 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -290,7 +290,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.AAPipeline.empty()) {
     AAManager AA;
     if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
-      report_fatal_error(Twine("unable to parse AA pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse AA pipeline description '") +
                          Conf.AAPipeline + "': " + toString(std::move(Err)));
     }
     // Register the AA manager first so that our version is the one used.
@@ -331,7 +331,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   // Parse a custom pipeline if asked to.
   if (!Conf.OptPipeline.empty()) {
     if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
-      report_fatal_error(Twine("unable to parse pass pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse pass pipeline description '") +
                          Conf.OptPipeline + "': " + toString(std::move(Err)));
     }
   } else if (IsThinLTO) {
@@ -415,7 +415,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
   if (!Conf.DwoDir.empty()) {
     std::error_code EC;
     if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
-      report_fatal_error(Twine("Failed to create directory ") + Conf.DwoDir +
+      reportFatalUsageError(Twine("Failed to create directory ") + Conf.DwoDir +
                          ": " + EC.message());
 
     DwoFile = Conf.DwoDir;
@@ -428,14 +428,14 @@ static void codegen(const Config &Conf, TargetMachine *TM,
     std::error_code EC;
     DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
     if (EC)
-      report_fatal_error(Twine("Failed to open ") + DwoFile + ": " +
+      reportFatalUsageError(Twine("Failed to open ") + DwoFile + ": " +
                          EC.message());
   }
 
   Expected<std::unique_ptr<CachedFileStream>> StreamOrErr =
       AddStream(Task, Mod.getModuleIdentifier());
   if (Error Err = StreamOrErr.takeError())
-    report_fatal_error(std::move(Err));
+    reportFatalUsageError(std::move(Err));
   std::unique_ptr<CachedFileStream> &Stream = *StreamOrErr;
   TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;
 
diff --git a/llvm/test/tools/llvm-lto2/X86/pipeline.ll b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
index 93f30d0ee61bc..9416ac5fd9fff 100644
--- a/llvm/test/tools/llvm-lto2/X86/pipeline.ll
+++ b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
@@ -28,13 +28,13 @@ define void @patatino() {
 ; CUSTOM-NEXT: }
 
 ; Check that invalid pipelines are caught as errors.
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -opt-pipeline foogoo 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=ERR
 
 ; ERR: LLVM ERROR: unable to parse pass pipeline description 'foogoo': unknown pass name 'foogoo'
 
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -aa-pipeline patatino \
 ; RUN:  -opt-pipeline lower-atomic 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=AAERR

@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-lld

Author: bd1976bris (bd1976bris)

Changes

Usage errors in LTOBackend.cpp were previously, misleadingly, reported as internal crashes.

This PR updates LTOBackend.cpp to use reportFatalUsageError for reporting usage-related issues.

LLVM Issue: #140953
Internal Tracker: TOOLCHAIN-17744


Full diff: https://github.com/llvm/llvm-project/pull/140955.diff

4 Files Affected:

  • (modified) lld/test/COFF/lto-cache-errors.ll (+2-2)
  • (modified) lld/test/ELF/lto/ltopasses-custom.ll (+2-2)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+5-5)
  • (modified) llvm/test/tools/llvm-lto2/X86/pipeline.ll (+2-2)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index a46190a81b623..44719e239d989 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -7,8 +7,8 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; RUN: chmod 444 %t.cache
 
-;; Check emit warnings when we can't create the cache dir
-; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+;; Check fatal usage error emitted when the cache dir can't be created.
+; RUN: not lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
 ; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
 
 target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/lld/test/ELF/lto/ltopasses-custom.ll b/lld/test/ELF/lto/ltopasses-custom.ll
index e37083ca8b8c7..da4a2d517f8e8 100644
--- a/lld/test/ELF/lto/ltopasses-custom.ll
+++ b/lld/test/ELF/lto/ltopasses-custom.ll
@@ -24,13 +24,13 @@ define void @barrier() {
 ; ATOMIC-NEXT: ret void
 
 ; Check that invalid passes are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=iamnotapass -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALID
 ; INVALID: unable to parse pass pipeline description 'iamnotapass': unknown pass name 'iamnotapass'
 
 ; Check that invalid AA pipelines are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=globaldce --lto-aa-pipeline=patatino \
 ; RUN:   -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALIDAA
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index b7db70b99bcbc..abda0147fe233 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -290,7 +290,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.AAPipeline.empty()) {
     AAManager AA;
     if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
-      report_fatal_error(Twine("unable to parse AA pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse AA pipeline description '") +
                          Conf.AAPipeline + "': " + toString(std::move(Err)));
     }
     // Register the AA manager first so that our version is the one used.
@@ -331,7 +331,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   // Parse a custom pipeline if asked to.
   if (!Conf.OptPipeline.empty()) {
     if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
-      report_fatal_error(Twine("unable to parse pass pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse pass pipeline description '") +
                          Conf.OptPipeline + "': " + toString(std::move(Err)));
     }
   } else if (IsThinLTO) {
@@ -415,7 +415,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
   if (!Conf.DwoDir.empty()) {
     std::error_code EC;
     if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
-      report_fatal_error(Twine("Failed to create directory ") + Conf.DwoDir +
+      reportFatalUsageError(Twine("Failed to create directory ") + Conf.DwoDir +
                          ": " + EC.message());
 
     DwoFile = Conf.DwoDir;
@@ -428,14 +428,14 @@ static void codegen(const Config &Conf, TargetMachine *TM,
     std::error_code EC;
     DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
     if (EC)
-      report_fatal_error(Twine("Failed to open ") + DwoFile + ": " +
+      reportFatalUsageError(Twine("Failed to open ") + DwoFile + ": " +
                          EC.message());
   }
 
   Expected<std::unique_ptr<CachedFileStream>> StreamOrErr =
       AddStream(Task, Mod.getModuleIdentifier());
   if (Error Err = StreamOrErr.takeError())
-    report_fatal_error(std::move(Err));
+    reportFatalUsageError(std::move(Err));
   std::unique_ptr<CachedFileStream> &Stream = *StreamOrErr;
   TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;
 
diff --git a/llvm/test/tools/llvm-lto2/X86/pipeline.ll b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
index 93f30d0ee61bc..9416ac5fd9fff 100644
--- a/llvm/test/tools/llvm-lto2/X86/pipeline.ll
+++ b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
@@ -28,13 +28,13 @@ define void @patatino() {
 ; CUSTOM-NEXT: }
 
 ; Check that invalid pipelines are caught as errors.
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -opt-pipeline foogoo 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=ERR
 
 ; ERR: LLVM ERROR: unable to parse pass pipeline description 'foogoo': unknown pass name 'foogoo'
 
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -aa-pipeline patatino \
 ; RUN:  -opt-pipeline lower-atomic 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=AAERR

@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-lld-elf

Author: bd1976bris (bd1976bris)

Changes

Usage errors in LTOBackend.cpp were previously, misleadingly, reported as internal crashes.

This PR updates LTOBackend.cpp to use reportFatalUsageError for reporting usage-related issues.

LLVM Issue: #140953
Internal Tracker: TOOLCHAIN-17744


Full diff: https://github.com/llvm/llvm-project/pull/140955.diff

4 Files Affected:

  • (modified) lld/test/COFF/lto-cache-errors.ll (+2-2)
  • (modified) lld/test/ELF/lto/ltopasses-custom.ll (+2-2)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+5-5)
  • (modified) llvm/test/tools/llvm-lto2/X86/pipeline.ll (+2-2)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index a46190a81b623..44719e239d989 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -7,8 +7,8 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; RUN: chmod 444 %t.cache
 
-;; Check emit warnings when we can't create the cache dir
-; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+;; Check fatal usage error emitted when the cache dir can't be created.
+; RUN: not lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
 ; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
 
 target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/lld/test/ELF/lto/ltopasses-custom.ll b/lld/test/ELF/lto/ltopasses-custom.ll
index e37083ca8b8c7..da4a2d517f8e8 100644
--- a/lld/test/ELF/lto/ltopasses-custom.ll
+++ b/lld/test/ELF/lto/ltopasses-custom.ll
@@ -24,13 +24,13 @@ define void @barrier() {
 ; ATOMIC-NEXT: ret void
 
 ; Check that invalid passes are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=iamnotapass -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALID
 ; INVALID: unable to parse pass pipeline description 'iamnotapass': unknown pass name 'iamnotapass'
 
 ; Check that invalid AA pipelines are rejected gracefully.
-; RUN: env LLD_IN_TEST=1 not --crash ld.lld -m elf_x86_64 %t.o -o /dev/null \
+; RUN: env LLD_IN_TEST=1 not ld.lld -m elf_x86_64 %t.o -o /dev/null \
 ; RUN:   --lto-newpm-passes=globaldce --lto-aa-pipeline=patatino \
 ; RUN:   -shared 2>&1 | \
 ; RUN:   FileCheck %s --check-prefix=INVALIDAA
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index b7db70b99bcbc..abda0147fe233 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -290,7 +290,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.AAPipeline.empty()) {
     AAManager AA;
     if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
-      report_fatal_error(Twine("unable to parse AA pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse AA pipeline description '") +
                          Conf.AAPipeline + "': " + toString(std::move(Err)));
     }
     // Register the AA manager first so that our version is the one used.
@@ -331,7 +331,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   // Parse a custom pipeline if asked to.
   if (!Conf.OptPipeline.empty()) {
     if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
-      report_fatal_error(Twine("unable to parse pass pipeline description '") +
+      reportFatalUsageError(Twine("unable to parse pass pipeline description '") +
                          Conf.OptPipeline + "': " + toString(std::move(Err)));
     }
   } else if (IsThinLTO) {
@@ -415,7 +415,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
   if (!Conf.DwoDir.empty()) {
     std::error_code EC;
     if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
-      report_fatal_error(Twine("Failed to create directory ") + Conf.DwoDir +
+      reportFatalUsageError(Twine("Failed to create directory ") + Conf.DwoDir +
                          ": " + EC.message());
 
     DwoFile = Conf.DwoDir;
@@ -428,14 +428,14 @@ static void codegen(const Config &Conf, TargetMachine *TM,
     std::error_code EC;
     DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
     if (EC)
-      report_fatal_error(Twine("Failed to open ") + DwoFile + ": " +
+      reportFatalUsageError(Twine("Failed to open ") + DwoFile + ": " +
                          EC.message());
   }
 
   Expected<std::unique_ptr<CachedFileStream>> StreamOrErr =
       AddStream(Task, Mod.getModuleIdentifier());
   if (Error Err = StreamOrErr.takeError())
-    report_fatal_error(std::move(Err));
+    reportFatalUsageError(std::move(Err));
   std::unique_ptr<CachedFileStream> &Stream = *StreamOrErr;
   TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;
 
diff --git a/llvm/test/tools/llvm-lto2/X86/pipeline.ll b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
index 93f30d0ee61bc..9416ac5fd9fff 100644
--- a/llvm/test/tools/llvm-lto2/X86/pipeline.ll
+++ b/llvm/test/tools/llvm-lto2/X86/pipeline.ll
@@ -28,13 +28,13 @@ define void @patatino() {
 ; CUSTOM-NEXT: }
 
 ; Check that invalid pipelines are caught as errors.
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -opt-pipeline foogoo 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=ERR
 
 ; ERR: LLVM ERROR: unable to parse pass pipeline description 'foogoo': unknown pass name 'foogoo'
 
-; RUN: not --crash llvm-lto2 run %t1.bc -o %t.o \
+; RUN: not llvm-lto2 run %t1.bc -o %t.o \
 ; RUN:  -r %t1.bc,patatino,px -aa-pipeline patatino \
 ; RUN:  -opt-pipeline lower-atomic 2>&1 | \
 ; RUN:  FileCheck %s --check-prefix=AAERR

@github-actions
Copy link

github-actions bot commented May 21, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@tru tru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bd1976bris bd1976bris merged commit b4d2e50 into llvm:main May 21, 2025
11 checks passed
@bd1976bris bd1976bris deleted the use_usage_err_in_lto_backend branch May 21, 2025 22:59
@MaskRay
Copy link
Member

MaskRay commented May 21, 2025

lgtm

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 22, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building lld,llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/32490

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'lld :: COFF/lto-cache-errors.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/build/buildbot/premerge-monolithic-linux/build/bin/opt -module-hash -module-summary /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/lto-cache-errors.ll -o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o # RUN: at line 5
+ /build/buildbot/premerge-monolithic-linux/build/bin/opt -module-hash -module-summary /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/lto-cache-errors.ll -o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o
/build/buildbot/premerge-monolithic-linux/build/bin/opt -module-hash -module-summary /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/Inputs/lto-cache.ll -o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o # RUN: at line 6
+ /build/buildbot/premerge-monolithic-linux/build/bin/opt -module-hash -module-summary /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/Inputs/lto-cache.ll -o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o
rm -Rf /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache && mkdir /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache # RUN: at line 7
+ rm -Rf /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
+ mkdir /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
chmod 444 /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache # RUN: at line 8
+ chmod 444 /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
not /build/buildbot/premerge-monolithic-linux/build/bin/lld-link /lldltocache:/build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache/nonexistant/ /out:/build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp3 /entry:main /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o 2>&1 | /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/lto-cache-errors.ll # RUN: at line 11
+ /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck /build/buildbot/premerge-monolithic-linux/llvm-project/lld/test/COFF/lto-cache-errors.ll
+ not /build/buildbot/premerge-monolithic-linux/build/bin/lld-link /lldltocache:/build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache/nonexistant/ /out:/build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp3 /entry:main /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o /build/buildbot/premerge-monolithic-linux/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented May 22, 2025

LLVM Buildbot has detected a new failure on builder lld-x86_64-ubuntu-fast running on as-builder-4 while building lld,llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/16898

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'lld :: COFF/lto-cache-errors.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -module-hash -module-summary /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/lto-cache-errors.ll -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o # RUN: at line 5
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -module-hash -module-summary /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/lto-cache-errors.ll -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -module-hash -module-summary /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/Inputs/lto-cache.ll -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o # RUN: at line 6
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/opt -module-hash -module-summary /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/Inputs/lto-cache.ll -o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o
rm -Rf /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache && mkdir /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache # RUN: at line 7
+ rm -Rf /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
+ mkdir /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
chmod 444 /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache # RUN: at line 8
+ chmod 444 /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache
not /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/lld-link /lldltocache:/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache/nonexistant/ /out:/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp3 /entry:main /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o 2>&1 | /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/lto-cache-errors.ll # RUN: at line 11
+ not /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/lld-link /lldltocache:/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.cache/nonexistant/ /out:/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp3 /entry:main /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp2.o /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/tools/lld/test/COFF/Output/lto-cache-errors.ll.tmp.o
+ /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/lld/test/COFF/lto-cache-errors.ll

--

********************


@Kewen12
Copy link
Contributor

Kewen12 commented May 22, 2025

Hi this PR causes check-lld failed that breaks out buildbots. I reverted locally and it passes. Please put up a fix or revert if necessary. Thanks!

TEST 'lld :: COFF/lto-cache-errors.ll' FAILED

Kewen12 added a commit to Kewen12/llvm-project that referenced this pull request May 22, 2025
shiltian pushed a commit that referenced this pull request May 22, 2025
…1000)

The PR causes check-lld fail:
>TEST 'lld :: COFF/lto-cache-errors.ll'

Tested on local revert and pass the check. 

Reverts #140955
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 22, 2025
…rrors" (#141000)

The PR causes check-lld fail:
>TEST 'lld :: COFF/lto-cache-errors.ll'

Tested on local revert and pass the check.

Reverts llvm/llvm-project#140955
@bd1976bris
Copy link
Collaborator Author

Hi this PR causes check-lld failed that breaks out buildbots. I reverted locally and it passes. Please put up a fix or revert if necessary. Thanks!

TEST 'lld :: COFF/lto-cache-errors.ll' FAILED

Hi @Kewen12. Thanks for reverting. I was originally going to combine this change with #140953 - in which I made lto-cache-errors.ll into a Windows only test. However, I spilt this part off to go in first. I must have dropped the lto-cache-errors.ll part of the change and, although I checked that the tests passed, I didn't notice that that this test was not being run as it was classified as UNSUPPORTED. Not sure why - maybe because it has: REQUIRES: non-root-user? Anyway, thanks.

@bd1976bris
Copy link
Collaborator Author

bd1976bris commented May 22, 2025

I was too quick to diagnose the issue. Whilst the UNSUPPORTED issue is present I checked and the test was being run when I tested on my dev setup before pushing. However, the failure is non-deterministic and so the test passed when I tested the patch before pushing.

@bd1976bris
Copy link
Collaborator Author

Digging into why the lto-cache-errors.ll test fails non-deterministically, I suspect that reportFatalUsageError can cause a crash if threads call reportFatalUsageError simultaneously (the ThinLTO cache dir is used from a multi-threaded context). I have observed this on Linux. It may also apply on Windows. This will need to be solved before we can use reportFatalUsageError for these errors. I don't have the time to work on this right now so I have unassigned myself from #140953 so that someone else can pick this up if they are interested. I am hopeful that I can land the other piece of this though: #140956.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lld:COFF lld:ELF lld LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants