From 776b0adaafa2198caa0ef6485e3e78a43620a58b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Jul 2024 14:48:42 +0200 Subject: [PATCH 1/2] Fix incorrect NDEBUG handling in LLVM bindings We currently compile our LLVM bindings using `-DNDEBUG` if debuginfo for LLVM is disabled. However, `NDEBUG` doesn't have any relation to debuginfo, it controls whether assertions are enabled. Rename the environment variable to `LLVM_ASSERTIONS` and drive it using the `llvm_assertions` option. Also drop the explicit `debug(false)` call, as cc already sets this up using the cargo `DEBUG` environment variable. --- compiler/rustc_llvm/build.rs | 3 +-- src/bootstrap/src/core/build_steps/compile.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 3aa852c83045d..4c1f78e6bee34 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -197,9 +197,8 @@ fn main() { cfg.define("LLVM_RUSTLLVM", None); } - if tracked_env_var_os("LLVM_NDEBUG").is_some() { + if tracked_env_var_os("LLVM_ASSERTIONS").is_none() { cfg.define("NDEBUG", None); - cfg.debug(false); } rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper")); diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 11a7a40453516..714a100428159 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1213,8 +1213,8 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect if builder.config.llvm_use_libcxx { cargo.env("LLVM_USE_LIBCXX", "1"); } - if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo { - cargo.env("LLVM_NDEBUG", "1"); + if builder.config.llvm_assertions { + cargo.env("LLVM_ASSERTIONS", "1"); } } From 8dfd3a455dc7d309f0c82dcb2e2f41da14f6c4af Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Jul 2024 14:52:26 +0200 Subject: [PATCH 2/2] Remove LLVMRustDIBuilderInsertDeclareAtEnd return value The return value changed from an Instruction to a DbgRecord in LLVM 19. As we don't actually use the result, drop the return value entirely to support both. --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 +- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 08e9e312827ce..e0bf6110cdf00 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2057,7 +2057,7 @@ extern "C" { AddrOpsCount: c_uint, DL: &'a DILocation, InsertAtEnd: &'a BasicBlock, - ) -> &'a Value; + ); pub fn LLVMRustDIBuilderCreateEnumerator<'a>( Builder: &DIBuilder<'a>, diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index b6790b7df500b..14757b27a3758 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -1137,20 +1137,15 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder, Builder->getOrCreateArray(ArrayRef(DataValue, Count)).get()); } -extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( +extern "C" void LLVMRustDIBuilderInsertDeclareAtEnd( LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo, uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL, LLVMBasicBlockRef InsertAtEnd) { - auto Result = Builder->insertDeclare( - unwrap(V), unwrap(VarInfo), - Builder->createExpression( - llvm::ArrayRef(AddrOps, AddrOpsCount)), - DebugLoc(cast(unwrap(DL))), unwrap(InsertAtEnd)); -#if LLVM_VERSION_GE(19, 0) - return wrap(Result.get()); -#else - return wrap(Result); -#endif + Builder->insertDeclare(unwrap(V), unwrap(VarInfo), + Builder->createExpression( + llvm::ArrayRef(AddrOps, AddrOpsCount)), + DebugLoc(cast(unwrap(DL))), + unwrap(InsertAtEnd)); } extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(