Answer
LLVM treats the "Unknown target triple" message as a fatal error emitted via llvm::report_fatal_error. This bypasses the regular DiagnosticHandler system and is delivered to the installed fatal error handler. Consequently, PassManagerBase::run aborts the entire pass pipeline on any fatal error, returning false and not executing further passes. No TargetOptions or PassManager settings affect this abort/continue decision; the only way to change the outcome is through the fatal error handler mechanism.
Confirmed facts
- The error originates in
TargetInfo when an invalid triple is passed to TargetMachine::createTargetMachine and is reported with llvm::report_fatal_error.
- According to the LLVM Programmer's Guide,
PassManagerBase::run returns false and stops processing further passes upon encountering a fatal error.
- The fatal error handler can be installed or replaced with
llvm::install_fatal_error_handler (or restored with llvm::reset_fatal_error_handler).
- DiagnosticHandler settings (e.g., via
LLVMContext::setDiagnosticHandler) do not capture errors that go through llvm::report_fatal_error.
Likely explanation
Because the fatal error handler is invoked directly by the LLVM core, it operates outside the diagnostic filtering pipeline. This design ensures that unrecoverable conditions such as an unknown target triple cannot be silenced by warning‑suppression settings, preserving the ability for the host program to react or terminate cleanly.
Steps to guarantee the fatal error is reported
- Install a custom fatal error handler early in your program (e.g., in
main or LLVM initialization).
- Inside the handler, log the message and then invoke the default handler to preserve LLVM’s standard abort behavior (or exit with a non‑zero status).
- Leave any
DiagnosticHandler configuration unchanged; it will not affect the fatal error path.
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
static void myFatalErrorHandler(void *UserData, const std::string &Reason,
bool GenCrashDiag) {
llvm::errs() << "LLVM fatal error: " << Reason << "\n";
// Call the default handler to abort or produce a crash dump.
llvm::reset_fatal_error_handler();
llvm::default_fatal_error_handler(UserData, Reason, GenCrashDiag);
}
int main(int argc, char **argv) {
llvm::install_fatal_error_handler(myFatalErrorHandler);
// ... LLVM usage that may trigger "Unknown target triple" ...
llvm::reset_fatal_error_handler(); // restore if needed
return 0;
}
Missing diagnostic detail
To confirm that the above approach matches your LLVM release, please specify the LLVM version you are using (e.g., 15.0.7, 16.0.0). The fatal error handler API is available from LLVM 3.9 onward; older versions may require a different method.