Skip to content

Commit 5eecd47

Browse files
committed
Use LLVMDIBuilderCreatePointerType
1 parent 9d350cd commit 5eecd47

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
@@ -156,17 +156,12 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
156156
"ptr_type={ptr_type}, pointee_type={pointee_type}",
157157
);
158158

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

171166
DINodeCreationResult { di_node, already_stored_in_typemap: false }
172167
}
@@ -214,17 +209,12 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
214209

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

229219
smallvec![
230220
build_field_di_node(
@@ -308,17 +298,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
308298
ty::FnPtr(..) => (cx.tcx.data_layout.pointer_size, cx.tcx.data_layout.pointer_align.abi),
309299
_ => unreachable!(),
310300
};
311-
let di_node = unsafe {
312-
llvm::LLVMRustDIBuilderCreatePointerType(
313-
DIB(cx),
314-
fn_di_node,
315-
size.bits(),
316-
align.bits() as u32,
317-
0, // Ignore DWARF address space.
318-
name.as_c_char_ptr(),
319-
name.len(),
320-
)
321-
};
301+
let di_node = DIB(cx).create_pointer_type(fn_di_node, size, align, &name);
322302

323303
DINodeCreationResult::new(di_node, false)
324304
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

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

18201830
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2171,16 +2181,6 @@ unsafe extern "C" {
21712181
Scope: Option<&'a DIScope>,
21722182
) -> &'a DIDerivedType;
21732183

2174-
pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
2175-
Builder: &DIBuilder<'a>,
2176-
PointeeTy: &'a DIType,
2177-
SizeInBits: u64,
2178-
AlignInBits: u32,
2179-
AddressSpace: c_uint,
2180-
Name: *const c_char,
2181-
NameLen: size_t,
2182-
) -> &'a DIDerivedType;
2183-
21842184
pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
21852185
Builder: &DIBuilder<'a>,
21862186
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)