Extract DIBuilderExt::create_expression

This commit is contained in:
Zalathar
2025-10-04 22:43:48 +10:00
parent b6ea8242fd
commit 45e9ebee31
2 changed files with 24 additions and 3 deletions

View File

@@ -0,0 +1,21 @@
use crate::llvm;
use crate::llvm::debuginfo::DIBuilder;
/// Extension trait for defining safe wrappers and helper methods on
/// `&DIBuilder<'ll>`, without requiring it to be defined in the same crate.
pub(crate) trait DIBuilderExt<'ll> {
fn as_di_builder(&self) -> &DIBuilder<'ll>;
fn create_expression(&self, addr_ops: &[u64]) -> &'ll llvm::Metadata {
let this = self.as_di_builder();
unsafe { llvm::LLVMDIBuilderCreateExpression(this, addr_ops.as_ptr(), addr_ops.len()) }
}
}
impl<'ll> DIBuilderExt<'ll> for &DIBuilder<'ll> {
fn as_di_builder(&self) -> &DIBuilder<'ll> {
self
}
// All other methods have default bodies that rely on `as_di_builder`.
}

View File

@@ -29,6 +29,7 @@ use smallvec::SmallVec;
use tracing::debug;
use self::create_scope_map::compute_mir_scopes;
pub(crate) use self::di_builder::DIBuilderExt;
pub(crate) use self::metadata::build_global_var_di_node;
use self::metadata::{
UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, spanned_type_di_node, type_di_node,
@@ -44,6 +45,7 @@ use crate::llvm::debuginfo::{
use crate::llvm::{self, Value};
mod create_scope_map;
mod di_builder;
mod dwarf_const;
mod gdb;
pub(crate) mod metadata;
@@ -181,9 +183,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
}
let di_builder = DIB(self.cx());
let addr_expr = unsafe {
llvm::LLVMDIBuilderCreateExpression(di_builder, addr_ops.as_ptr(), addr_ops.len())
};
let addr_expr = di_builder.create_expression(&addr_ops);
unsafe {
llvm::LLVMDIBuilderInsertDeclareRecordAtEnd(
di_builder,