From 7b2a5cb692bef19a3cc7ccd03dec0105afb80f14 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 3 Nov 2026 13:25:49 +0100 Subject: [PATCH] Use LLVMParseCommandLineOptionsWithError in LLVMRustSetLLVMOptions It will ensure library options are picked up by new contexts, and lets us handle errors explicitly. --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index e6cb3c991e491..53b77729a7425 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -1,6 +1,7 @@ #include "LLVMWrapper.h" #include "llvm-c/Core.h" +#include "llvm-c/Support.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" @@ -449,7 +450,17 @@ extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) { if (Initialized) return; Initialized = true; +#if LLVM_VERSION_GE(24, 0) + char *Err; + if (LLVMParseCommandLineOptionsWithError(Argc, Argv, "", &Err)) { + // FIXME: Report the error via Rust's diagnostics infrastructure. + errs() << Err; + LLVMDisposeMessage(Err); + exit(1); + } +#else cl::ParseCommandLineOptions(Argc, Argv); +#endif } enum class LLVMRustFileType {