Skip to content

Commit 70fcef3

Browse files
committed
Use LLVMDIBuilderCreateBasicType
1 parent bd6dd53 commit 70fcef3

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs

+19
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,23 @@ impl<'ll> DIBuilder<'ll> {
7373
)
7474
}
7575
}
76+
77+
pub(crate) fn create_basic_type(
78+
&self,
79+
name: &str,
80+
size: Size,
81+
dwarf_type_encoding: u32,
82+
flags: DIFlags,
83+
) -> &'ll Metadata {
84+
unsafe {
85+
llvm::LLVMDIBuilderCreateBasicType(
86+
self,
87+
name.as_ptr(),
88+
name.len(),
89+
size.bits(),
90+
dwarf_type_encoding,
91+
flags,
92+
)
93+
}
94+
}
7695
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+17-29
Original file line numberDiff line numberDiff line change
@@ -471,26 +471,22 @@ pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) ->
471471
// FIXME(mw): Cache this via a regular UniqueTypeId instead of an extra field in the debug context.
472472
fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
473473
*debug_context(cx).recursion_marker_type.get_or_init(move || {
474-
unsafe {
475-
// The choice of type here is pretty arbitrary -
476-
// anything reading the debuginfo for a recursive
477-
// type is going to see *something* weird - the only
478-
// question is what exactly it will see.
479-
//
480-
// FIXME: the name `<recur_type>` does not fit the naming scheme
481-
// of other types.
482-
//
483-
// FIXME: it might make sense to use an actual pointer type here
484-
// so that debuggers can show the address.
485-
let name = "<recur_type>";
486-
llvm::LLVMRustDIBuilderCreateBasicType(
487-
DIB(cx),
488-
name.as_c_char_ptr(),
489-
name.len(),
490-
cx.tcx.data_layout.pointer_size.bits(),
491-
dwarf_const::DW_ATE_unsigned,
492-
)
493-
}
474+
// The choice of type here is pretty arbitrary -
475+
// anything reading the debuginfo for a recursive
476+
// type is going to see *something* weird - the only
477+
// question is what exactly it will see.
478+
//
479+
// FIXME: the name `<recur_type>` does not fit the naming scheme
480+
// of other types.
481+
//
482+
// FIXME: it might make sense to use an actual pointer type here
483+
// so that debuggers can show the address.
484+
DIB(cx).create_basic_type(
485+
"<recur_type>",
486+
cx.tcx.data_layout.pointer_size,
487+
dwarf_const::DW_ATE_unsigned,
488+
DIFlags::FlagZero,
489+
)
494490
})
495491
}
496492

@@ -772,15 +768,7 @@ fn build_basic_type_di_node<'ll, 'tcx>(
772768
_ => bug!("debuginfo::build_basic_type_di_node - `t` is invalid type"),
773769
};
774770

775-
let ty_di_node = unsafe {
776-
llvm::LLVMRustDIBuilderCreateBasicType(
777-
DIB(cx),
778-
name.as_c_char_ptr(),
779-
name.len(),
780-
cx.size_of(t).bits(),
781-
encoding,
782-
)
783-
};
771+
let ty_di_node = DIB(cx).create_basic_type(name, cx.size_of(t), encoding, DIFlags::FlagZero);
784772

785773
if !cpp_like_debuginfo {
786774
return DINodeCreationResult::new(ty_di_node, false);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,15 @@ unsafe extern "C" {
18011801
Subscripts: *const &'ll Metadata,
18021802
NumSubscripts: c_uint,
18031803
) -> &'ll Metadata;
1804+
1805+
pub(crate) fn LLVMDIBuilderCreateBasicType<'ll>(
1806+
Builder: &DIBuilder<'ll>,
1807+
Name: *const c_uchar,
1808+
NameLen: size_t,
1809+
SizeInBits: u64,
1810+
Encoding: c_uint, // `LLVMDWARFTypeEncoding`
1811+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1812+
) -> &'ll Metadata;
18041813
}
18051814

18061815
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2133,14 +2142,6 @@ unsafe extern "C" {
21332142
TParam: &'a DIArray,
21342143
) -> &'a DISubprogram;
21352144

2136-
pub fn LLVMRustDIBuilderCreateBasicType<'a>(
2137-
Builder: &DIBuilder<'a>,
2138-
Name: *const c_char,
2139-
NameLen: size_t,
2140-
SizeInBits: u64,
2141-
Encoding: c_uint,
2142-
) -> &'a DIBasicType;
2143-
21442145
pub fn LLVMRustDIBuilderCreateTypedef<'a>(
21452146
Builder: &DIBuilder<'a>,
21462147
Type: &'a DIBasicType,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1074,14 +1074,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod(
10741074
return wrap(Sub);
10751075
}
10761076

1077-
extern "C" LLVMMetadataRef
1078-
LLVMRustDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
1079-
size_t NameLen, uint64_t SizeInBits,
1080-
unsigned Encoding) {
1081-
return wrap(unwrap(Builder)->createBasicType(StringRef(Name, NameLen),
1082-
SizeInBits, Encoding));
1083-
}
1084-
10851077
extern "C" LLVMMetadataRef
10861078
LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
10871079
const char *Name, size_t NameLen,

0 commit comments

Comments
 (0)