Rollup merge of #127654 - nikic:llvm-ndebug-fix, r=cuviper

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.

Split the LLVM_NDEBUG environment variable into two, so that assertions and debuginfo are controlled independently.

After this change, `LLVMRustDIBuilderInsertDeclareAtEnd` triggers an assertion failure on LLVM 19 due to an incorrect cast. Fix it by removing the unused return value entirely.

r? `@cuviper`
This commit is contained in:
Jacob Pratt 2024-07-13 00:24:35 -04:00 committed by GitHub
commit cb1ccc1842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 16 deletions

View File

@ -2057,7 +2057,7 @@ extern "C" {
AddrOpsCount: c_uint, AddrOpsCount: c_uint,
DL: &'a DILocation, DL: &'a DILocation,
InsertAtEnd: &'a BasicBlock, InsertAtEnd: &'a BasicBlock,
) -> &'a Value; );
pub fn LLVMRustDIBuilderCreateEnumerator<'a>( pub fn LLVMRustDIBuilderCreateEnumerator<'a>(
Builder: &DIBuilder<'a>, Builder: &DIBuilder<'a>,

View File

@ -197,9 +197,8 @@ fn main() {
cfg.define("LLVM_RUSTLLVM", None); 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.define("NDEBUG", None);
cfg.debug(false);
} }
rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper")); rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper"));

View File

@ -1137,20 +1137,15 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get()); Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get());
} }
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( extern "C" void LLVMRustDIBuilderInsertDeclareAtEnd(
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo, LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL, uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
LLVMBasicBlockRef InsertAtEnd) { LLVMBasicBlockRef InsertAtEnd) {
auto Result = Builder->insertDeclare( Builder->insertDeclare(unwrap(V), unwrap<DILocalVariable>(VarInfo),
unwrap(V), unwrap<DILocalVariable>(VarInfo),
Builder->createExpression( Builder->createExpression(
llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)), llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)),
DebugLoc(cast<MDNode>(unwrap(DL))), unwrap(InsertAtEnd)); DebugLoc(cast<MDNode>(unwrap(DL))),
#if LLVM_VERSION_GE(19, 0) unwrap(InsertAtEnd));
return wrap(Result.get<llvm::Instruction *>());
#else
return wrap(Result);
#endif
} }
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(

View File

@ -1213,8 +1213,8 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
if builder.config.llvm_use_libcxx { if builder.config.llvm_use_libcxx {
cargo.env("LLVM_USE_LIBCXX", "1"); cargo.env("LLVM_USE_LIBCXX", "1");
} }
if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo { if builder.config.llvm_assertions {
cargo.env("LLVM_NDEBUG", "1"); cargo.env("LLVM_ASSERTIONS", "1");
} }
} }