Skip to content

Commit b1c3e11

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 cd63070 commit b1c3e11

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
@@ -1782,6 +1782,12 @@ unsafe extern "C" {
17821782
Data: *const Option<&'ll Metadata>,
17831783
NumElements: size_t,
17841784
) -> &'ll Metadata;
1785+
1786+
pub(crate) fn LLVMDIBuilderCreateExpression<'ll>(
1787+
Builder: &DIBuilder<'ll>,
1788+
Addr: *const u64,
1789+
Length: size_t,
1790+
) -> &'ll Metadata;
17851791
}
17861792

17871793
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2160,14 +2166,15 @@ unsafe extern "C" {
21602166
AlignInBits: u32,
21612167
) -> &'a DIVariable;
21622168

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

21732180
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
@@ -1045,15 +1045,12 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
10451045
}
10461046
}
10471047

1048-
extern "C" void LLVMRustDIBuilderInsertDeclareAtEnd(
1049-
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
1050-
uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
1051-
LLVMBasicBlockRef InsertAtEnd) {
1052-
Builder->insertDeclare(unwrap(V), unwrap<DILocalVariable>(VarInfo),
1053-
Builder->createExpression(
1054-
llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)),
1055-
DebugLoc(cast<MDNode>(unwrap(DL))),
1056-
unwrap(InsertAtEnd));
1048+
extern "C" void LLVMRustDIBuilderInsertDeclareRecordAtEnd(
1049+
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1050+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
1051+
unwrap(Builder)->insertDeclare(
1052+
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1053+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc), unwrap(Block));
10571054
}
10581055

10591056
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(

0 commit comments

Comments
 (0)