Skip to content

Commit f02f863

Browse files
committed
Use LLVMDIBuilderCreateExpression and adjust our insert function
The `LLVMDIBuilderInsertDeclareRecordAtEnd` function requires LLVM 19, so we can't use it yet, but we can adjust our own wrapper function to resemble it as closely as possible.
1 parent 955d19c commit f02f863

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,17 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
172172
addr_ops.push((fragment.end - fragment.start).bits() as u64);
173173
}
174174

175+
let expr = unsafe {
176+
llvm::LLVMDIBuilderCreateExpression(DIB(self.cx()), addr_ops.as_ptr(), addr_ops.len())
177+
};
178+
175179
unsafe {
176180
// FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
177-
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
181+
llvm::LLVMRustDIBuilderInsertDeclareRecordAtEnd(
178182
DIB(self.cx()),
179183
variable_alloca,
180184
dbg_var,
181-
addr_ops.as_ptr(),
182-
addr_ops.len() as c_uint,
185+
expr,
183186
dbg_loc,
184187
self.llbb(),
185188
);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,12 @@ unsafe extern "C" {
17841784
Data: *const Option<&'ll Metadata>,
17851785
NumElements: size_t,
17861786
) -> &'ll Metadata;
1787+
1788+
pub(crate) fn LLVMDIBuilderCreateExpression<'ll>(
1789+
Builder: &DIBuilder<'ll>,
1790+
Addr: *const u64,
1791+
Length: size_t,
1792+
) -> &'ll Metadata;
17871793
}
17881794

17891795
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2162,14 +2168,15 @@ unsafe extern "C" {
21622168
AlignInBits: u32,
21632169
) -> &'a DIVariable;
21642170

2165-
pub fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
2166-
Builder: &DIBuilder<'a>,
2167-
Val: &'a Value,
2168-
VarInfo: &'a DIVariable,
2169-
AddrOps: *const u64,
2170-
AddrOpsCount: c_uint,
2171-
DL: &'a DILocation,
2172-
InsertAtEnd: &'a BasicBlock,
2171+
/// Mostly equivalent to `LLVMDIBuilderInsertDeclareRecordAtEnd` in LLVM 19,
2172+
/// except that this works on LLVM 18 and also doesn't return a value.
2173+
pub(crate) fn LLVMRustDIBuilderInsertDeclareRecordAtEnd<'ll>(
2174+
Builder: &DIBuilder<'ll>,
2175+
Storage: &'ll Value,
2176+
VarInfo: &'ll Metadata,
2177+
Expr: &'ll Metadata,
2178+
DebugLoc: &'ll Metadata,
2179+
Block: &'ll BasicBlock,
21732180
);
21742181

21752182
pub fn LLVMRustDIBuilderCreateEnumerator<'a>(

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,15 +1058,12 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
10581058
}
10591059
}
10601060

1061-
extern "C" void LLVMRustDIBuilderInsertDeclareAtEnd(
1062-
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
1063-
uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
1064-
LLVMBasicBlockRef InsertAtEnd) {
1065-
Builder->insertDeclare(unwrap(V), unwrap<DILocalVariable>(VarInfo),
1066-
Builder->createExpression(
1067-
llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)),
1068-
DebugLoc(cast<MDNode>(unwrap(DL))),
1069-
unwrap(InsertAtEnd));
1061+
extern "C" void LLVMRustDIBuilderInsertDeclareRecordAtEnd(
1062+
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1063+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
1064+
unwrap(Builder)->insertDeclare(
1065+
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1066+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), unwrap(Block));
10701067
}
10711068

10721069
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(

0 commit comments

Comments
 (0)