Skip to content

[LLVM][Windows] Elide PrettyStackTrace output for usage errors #140956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/tools/clang-repl/ClangRepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void LLVMErrorHandler(void *UserData, const char *Message,

// Run the interrupt handlers to make sure any special cleanups get done, in
// particular that we remove files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
llvm::sys::RunInterruptHandlers(/*ExecuteSignalHandlers=*/true);

// We cannot recover from llvm errors. When reporting a fatal error, exit
// with status 70 to generate crash diagnostics. For BSD systems this is
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void LLVMErrorHandler(void *UserData, const char *Message,

// Run the interrupt handlers to make sure any special cleanups get done, in
// particular that we remove files registered with RemoveFileOnSignal.
llvm::sys::RunInterruptHandlers();
llvm::sys::RunInterruptHandlers(/*ExecuteSignalHandlers=*/true);

// We cannot recover from llvm errors. When reporting a fatal error, exit
// with status 70 to generate crash diagnostics. For BSD systems this is
Expand Down
12 changes: 8 additions & 4 deletions lld/test/ELF/lto/ltopasses-custom.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ 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 \
; The --implicit-check-not arguments verify that no crash-style output is shown.
; 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
; RUN: FileCheck %s --check-prefix=INVALID \
; RUN: --ignore-case --implicit-check-not=bug --implicit-check-not=crash
; 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 \
; The --implicit-check-not arguments verify that no crash-style output is shown.
; 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
; RUN: FileCheck %s --check-prefix=INVALIDAA \
; RUN: --ignore-case --implicit-check-not=bug --implicit-check-not=crash
; INVALIDAA: unknown alias analysis name 'patatino'
3 changes: 3 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Changes to LLVM infrastructure
* Added the support for ``fmaximum`` and ``fminimum`` in ``atomicrmw`` instruction. The
comparison is expected to match the behavior of ``llvm.maximum.*`` and
``llvm.minimum.*`` respectively.
* On Windows, fatal usage errors no longer invoke LLVM's signal handlers.
As a result, the default "please report a bug" message from the `PrettyStackTrace`
signal handler is no longer emitted.

Changes to building LLVM
------------------------
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/Signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace sys {

/// This function runs all the registered interrupt handlers, including the
/// removal of files registered by RemoveFileOnSignal.
LLVM_ABI void RunInterruptHandlers();
LLVM_ABI void RunInterruptHandlers(bool ExecuteSignalHandlers);

/// This function registers signal handlers to ensure that if a signal gets
/// delivered that the named file is removed.
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/LTO/LTOBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ 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 '") +
Conf.AAPipeline + "': " + toString(std::move(Err)));
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.
FAM.registerPass([&] { return std::move(AA); });
Expand Down Expand Up @@ -331,8 +331,9 @@ 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 '") +
Conf.OptPipeline + "': " + toString(std::move(Err)));
reportFatalUsageError(
Twine("unable to parse pass pipeline description '") +
Conf.OptPipeline + "': " + toString(std::move(Err)));
}
} else if (IsThinLTO) {
MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
// If we reached here, we are failing ungracefully. Run the interrupt handlers
// to make sure any special cleanups get done, in particular that we remove
// files registered with RemoveFileOnSignal.
sys::RunInterruptHandlers();
sys::RunInterruptHandlers(GenCrashDiag);

if (GenCrashDiag)
abort();
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Support/Unix/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ static void InfoSignalHandler(int Sig) {
CurrentInfoFunction();
}

void llvm::sys::RunInterruptHandlers() { RemoveFilesToRemove(); }
void llvm::sys::RunInterruptHandlers(bool /*ExecuteSignalHandlers*/) {
RemoveFilesToRemove();
}

void llvm::sys::SetInterruptFunction(void (*IF)()) {
InterruptFunction.exchange(IF);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Support/Windows/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,13 @@ static void Cleanup(bool ExecuteSignalHandlers) {
LeaveCriticalSection(&CriticalSection);
}

void llvm::sys::RunInterruptHandlers() {
void llvm::sys::RunInterruptHandlers(bool ExecuteSignalHandlers) {
// The interrupt handler may be called from an interrupt, but it may also be
// called manually (such as the case of report_fatal_error with no registered
// error handler). We must ensure that the critical section is properly
// initialized.
InitializeThreading();
Cleanup(true);
Cleanup(ExecuteSignalHandlers);
}

/// Find the Windows Registry Key for a given location.
Expand Down Expand Up @@ -847,7 +847,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
}

static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
Cleanup(true);
Cleanup(/*ExecuteSignalHandlers=*/true);

// Write out the exception code.
if (ep && ep->ExceptionRecord)
Expand Down Expand Up @@ -887,7 +887,7 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) {
// This function is only ever called when a CTRL-C or similar control signal
// is fired. Killing a process in this way is normal, so don't trigger the
// signal handlers.
Cleanup(false);
Cleanup(/*ExecuteSignalHandlers=*/false);

// If an interrupt function has been set, go and run one it; otherwise,
// the process dies.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/TableGen/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
// Run file cleanup handlers and then exit fatally (with non-zero exit code).
[[noreturn]] inline static void fatal_exit() {
// The following call runs the file cleanup handlers.
sys::RunInterruptHandlers();
sys::RunInterruptHandlers(/*ExecuteSignalHandlers=*/true);
std::exit(1);
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/tools/llvm-lto2/X86/pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3836,7 +3836,7 @@ void mlir::tblgen::generateOpFormat(const Operator &constOp, OpClass &opClass,
// Exit the process if format errors are treated as fatal.
if (formatErrorIsFatal) {
// Invoke the interrupt handlers to run the file cleanup handlers.
llvm::sys::RunInterruptHandlers();
llvm::sys::RunInterruptHandlers(/*ExecuteSignalHandlers=*/true);
std::exit(1);
}
return;
Expand Down