Skip to content

Commit 1686818

Browse files
committed
Use LLVMDIBuilderCreatePointerType
1 parent 331692d commit 1686818

File tree

4 files changed

+43
-52
lines changed

4 files changed

+43
-52
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

+13-33
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(
@@ -306,17 +296,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
306296
ty::FnPtr(..) => (cx.tcx.data_layout.pointer_size, cx.tcx.data_layout.pointer_align.abi),
307297
_ => unreachable!(),
308298
};
309-
let di_node = unsafe {
310-
llvm::LLVMRustDIBuilderCreatePointerType(
311-
DIB(cx),
312-
fn_di_node,
313-
size.bits(),
314-
align.bits() as u32,
315-
0, // Ignore DWARF address space.
316-
name.as_c_char_ptr(),
317-
name.len(),
318-
)
319-
};
299+
let di_node = DIB(cx).create_pointer_type(fn_di_node, size, align, &name);
320300

321301
DINodeCreationResult::new(di_node, false)
322302
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

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

18181828
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2169,16 +2179,6 @@ unsafe extern "C" {
21692179
Scope: Option<&'a DIScope>,
21702180
) -> &'a DIDerivedType;
21712181

2172-
pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
2173-
Builder: &DIBuilder<'a>,
2174-
PointeeTy: &'a DIType,
2175-
SizeInBits: u64,
2176-
AlignInBits: u32,
2177-
AddressSpace: c_uint,
2178-
Name: *const c_char,
2179-
NameLen: size_t,
2180-
) -> &'a DIDerivedType;
2181-
21822182
pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
21832183
Builder: &DIBuilder<'a>,
21842184
Scope: Option<&'a DIDescriptor>,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1057,15 +1057,6 @@ LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
10571057
LineNo, unwrapDIPtr<DIScope>(Scope)));
10581058
}
10591059

1060-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
1061-
LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits,
1062-
uint32_t AlignInBits, unsigned AddressSpace, const char *Name,
1063-
size_t NameLen) {
1064-
return wrap(unwrap(Builder)->createPointerType(
1065-
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
1066-
StringRef(Name, NameLen)));
1067-
}
1068-
10691060
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType(
10701061
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
10711062
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,

0 commit comments

Comments
 (0)