Skip to content

Commit d9273a9

Browse files
committed
Use LLVMDIBuilderCreatePointerType
1 parent 70fcef3 commit d9273a9

File tree

4 files changed

+45
-57
lines changed

4 files changed

+45
-57
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs

+20
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,24 @@ impl<'ll> DIBuilder<'ll> {
9292
)
9393
}
9494
}
95+
96+
pub(crate) fn create_pointer_type(
97+
&self,
98+
pointee_type: &'ll Metadata,
99+
size: Size,
100+
align: Align,
101+
name: &str,
102+
) -> &'ll Metadata {
103+
unsafe {
104+
llvm::LLVMDIBuilderCreatePointerType(
105+
self,
106+
pointee_type,
107+
size.bits(),
108+
align.bits() as u32,
109+
0, // ("DWARF address space"; default is 0)
110+
name.as_ptr(),
111+
name.len(),
112+
)
113+
}
114+
}
95115
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+15-38
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,12 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
154154
"ptr_type={ptr_type}, pointee_type={pointee_type}",
155155
);
156156

157-
let di_node = unsafe {
158-
llvm::LLVMRustDIBuilderCreatePointerType(
159-
DIB(cx),
160-
pointee_type_di_node,
161-
data_layout.pointer_size.bits(),
162-
data_layout.pointer_align.abi.bits() as u32,
163-
0, // Ignore DWARF address space.
164-
ptr_type_debuginfo_name.as_c_char_ptr(),
165-
ptr_type_debuginfo_name.len(),
166-
)
167-
};
157+
let di_node = DIB(cx).create_pointer_type(
158+
pointee_type_di_node,
159+
data_layout.pointer_size,
160+
data_layout.pointer_align.abi,
161+
&ptr_type_debuginfo_name,
162+
);
168163

169164
DINodeCreationResult { di_node, already_stored_in_typemap: false }
170165
}
@@ -212,17 +207,12 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
212207

213208
// The data pointer type is a regular, thin pointer, regardless of whether this
214209
// is a slice or a trait object.
215-
let data_ptr_type_di_node = unsafe {
216-
llvm::LLVMRustDIBuilderCreatePointerType(
217-
DIB(cx),
218-
pointee_type_di_node,
219-
addr_field.size.bits(),
220-
addr_field.align.abi.bits() as u32,
221-
0, // Ignore DWARF address space.
222-
std::ptr::null(),
223-
0,
224-
)
225-
};
210+
let data_ptr_type_di_node = DIB(cx).create_pointer_type(
211+
pointee_type_di_node,
212+
addr_field.size,
213+
addr_field.align.abi,
214+
"",
215+
);
226216

227217
smallvec![
228218
build_field_di_node(
@@ -302,24 +292,11 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
302292
// This is actually a function pointer, so wrap it in pointer DI.
303293
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
304294
let (size, align) = match fn_ty.kind() {
305-
ty::FnDef(..) => (0, 1),
306-
ty::FnPtr(..) => (
307-
cx.tcx.data_layout.pointer_size.bits(),
308-
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
309-
),
295+
ty::FnDef(..) => (Size::ZERO, Align::ONE),
296+
ty::FnPtr(..) => (cx.tcx.data_layout.pointer_size, cx.tcx.data_layout.pointer_align.abi),
310297
_ => unreachable!(),
311298
};
312-
let di_node = unsafe {
313-
llvm::LLVMRustDIBuilderCreatePointerType(
314-
DIB(cx),
315-
fn_di_node,
316-
size,
317-
align,
318-
0, // Ignore DWARF address space.
319-
name.as_c_char_ptr(),
320-
name.len(),
321-
)
322-
};
299+
let di_node = DIB(cx).create_pointer_type(fn_di_node, size, align, &name);
323300

324301
DINodeCreationResult::new(di_node, false)
325302
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,16 @@ unsafe extern "C" {
18101810
Encoding: c_uint, // `LLVMDWARFTypeEncoding`
18111811
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
18121812
) -> &'ll Metadata;
1813+
1814+
pub(crate) fn LLVMDIBuilderCreatePointerType<'ll>(
1815+
Builder: &DIBuilder<'ll>,
1816+
PointeeTy: &'ll Metadata,
1817+
SizeInBits: u64,
1818+
AlignInBits: u32,
1819+
AddressSpace: c_uint,
1820+
Name: *const c_uchar,
1821+
NameLen: size_t,
1822+
) -> &'ll Metadata;
18131823
}
18141824

18151825
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2152,16 +2162,6 @@ unsafe extern "C" {
21522162
Scope: Option<&'a DIScope>,
21532163
) -> &'a DIDerivedType;
21542164

2155-
pub fn LLVMRustDIBuilderCreatePointerType<'a>(
2156-
Builder: &DIBuilder<'a>,
2157-
PointeeTy: &'a DIType,
2158-
SizeInBits: u64,
2159-
AlignInBits: u32,
2160-
AddressSpace: c_uint,
2161-
Name: *const c_char,
2162-
NameLen: size_t,
2163-
) -> &'a DIDerivedType;
2164-
21652165
pub fn LLVMRustDIBuilderCreateStructType<'a>(
21662166
Builder: &DIBuilder<'a>,
21672167
Scope: Option<&'a DIDescriptor>,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1084,15 +1084,6 @@ LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
10841084
LineNo, unwrapDIPtr<DIScope>(Scope)));
10851085
}
10861086

1087-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
1088-
LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits,
1089-
uint32_t AlignInBits, unsigned AddressSpace, const char *Name,
1090-
size_t NameLen) {
1091-
return wrap(unwrap(Builder)->createPointerType(
1092-
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
1093-
StringRef(Name, NameLen)));
1094-
}
1095-
10961087
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType(
10971088
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
10981089
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,

0 commit comments

Comments
 (0)