Use LLVMDIBuilderCreatePointerType

This commit is contained in:
Zalathar
2025-09-16 20:09:34 +10:00
parent 3e9048d9a4
commit bae6fde270
3 changed files with 45 additions and 52 deletions

View File

@@ -173,17 +173,13 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
"ptr_type={ptr_type}, pointee_type={pointee_type}",
);
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
pointer_size.bits(),
pointer_align.abi.bits() as u32,
0, // Ignore DWARF address space.
ptr_type_debuginfo_name.as_c_char_ptr(),
ptr_type_debuginfo_name.len(),
)
};
let di_node = create_pointer_type(
cx,
pointee_type_di_node,
pointer_size,
pointer_align.abi,
&ptr_type_debuginfo_name,
);
DINodeCreationResult { di_node, already_stored_in_typemap: false }
}
@@ -231,17 +227,13 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
// The data pointer type is a regular, thin pointer, regardless of whether this
// is a slice or a trait object.
let data_ptr_type_di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
addr_field.size.bits(),
addr_field.align.abi.bits() as u32,
0, // Ignore DWARF address space.
std::ptr::null(),
0,
)
};
let data_ptr_type_di_node = create_pointer_type(
cx,
pointee_type_di_node,
addr_field.size,
addr_field.align.abi,
"",
);
smallvec![
build_field_di_node(
@@ -327,17 +319,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
}
_ => unreachable!(),
};
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
fn_di_node,
size.bits(),
align.bits() as u32,
0, // Ignore DWARF address space.
name.as_c_char_ptr(),
name.len(),
)
};
let di_node = create_pointer_type(cx, fn_di_node, size, align, &name);
DINodeCreationResult::new(di_node, false)
}
@@ -357,6 +339,26 @@ pub(super) fn create_subroutine_type<'ll>(
}
}
fn create_pointer_type<'ll>(
cx: &CodegenCx<'ll, '_>,
pointee_ty: &'ll llvm::Metadata,
size: Size,
align: Align,
name: &str,
) -> &'ll llvm::Metadata {
unsafe {
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
pointee_ty,
size.bits(),
align.bits() as u32,
0, // Ignore DWARF address space.
name.as_ptr(),
name.len(),
)
}
}
/// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs
/// we with the correct type name (e.g. "dyn SomeTrait<Foo, Item=u32> + Sync").
fn build_dyn_type_di_node<'ll, 'tcx>(

View File

@@ -1913,6 +1913,16 @@ unsafe extern "C" {
Encoding: c_uint, // (`LLVMDWARFTypeEncoding`)
Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)
) -> &'ll Metadata;
pub(crate) fn LLVMDIBuilderCreatePointerType<'ll>(
Builder: &DIBuilder<'ll>,
PointeeTy: &'ll Metadata,
SizeInBits: u64,
AlignInBits: u32,
AddressSpace: c_uint, // (optional DWARF address space; default is 0)
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
) -> &'ll Metadata;
}
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2258,16 +2268,6 @@ unsafe extern "C" {
Scope: Option<&'a DIScope>,
) -> &'a DIDerivedType;
pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
Builder: &DIBuilder<'a>,
PointeeTy: &'a DIType,
SizeInBits: u64,
AlignInBits: u32,
AddressSpace: c_uint,
Name: *const c_char,
NameLen: size_t,
) -> &'a DIDerivedType;
pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
Builder: &DIBuilder<'a>,
Scope: Option<&'a DIDescriptor>,