Skip to content

Commit 45e9ebe

Browse files
committed
Extract DIBuilderExt::create_expression
1 parent b6ea824 commit 45e9ebe

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::llvm;
2+
use crate::llvm::debuginfo::DIBuilder;
3+
4+
/// Extension trait for defining safe wrappers and helper methods on
5+
/// `&DIBuilder<'ll>`, without requiring it to be defined in the same crate.
6+
pub(crate) trait DIBuilderExt<'ll> {
7+
fn as_di_builder(&self) -> &DIBuilder<'ll>;
8+
9+
fn create_expression(&self, addr_ops: &[u64]) -> &'ll llvm::Metadata {
10+
let this = self.as_di_builder();
11+
unsafe { llvm::LLVMDIBuilderCreateExpression(this, addr_ops.as_ptr(), addr_ops.len()) }
12+
}
13+
}
14+
15+
impl<'ll> DIBuilderExt<'ll> for &DIBuilder<'ll> {
16+
fn as_di_builder(&self) -> &DIBuilder<'ll> {
17+
self
18+
}
19+
20+
// All other methods have default bodies that rely on `as_di_builder`.
21+
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use smallvec::SmallVec;
2929
use tracing::debug;
3030

3131
use self::create_scope_map::compute_mir_scopes;
32+
pub(crate) use self::di_builder::DIBuilderExt;
3233
pub(crate) use self::metadata::build_global_var_di_node;
3334
use self::metadata::{
3435
UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, spanned_type_di_node, type_di_node,
@@ -44,6 +45,7 @@ use crate::llvm::debuginfo::{
4445
use crate::llvm::{self, Value};
4546

4647
mod create_scope_map;
48+
mod di_builder;
4749
mod dwarf_const;
4850
mod gdb;
4951
pub(crate) mod metadata;
@@ -181,9 +183,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
181183
}
182184

183185
let di_builder = DIB(self.cx());
184-
let addr_expr = unsafe {
185-
llvm::LLVMDIBuilderCreateExpression(di_builder, addr_ops.as_ptr(), addr_ops.len())
186-
};
186+
let addr_expr = di_builder.create_expression(&addr_ops);
187187
unsafe {
188188
llvm::LLVMDIBuilderInsertDeclareRecordAtEnd(
189189
di_builder,

0 commit comments

Comments
 (0)