Skip to content

Commit 9fab758

Browse files
committed
Use LLVMDIBuilderCreateBasicType
1 parent 8206a78 commit 9fab758

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

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

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

784772
if !cpp_like_debuginfo {
785773
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
@@ -1806,6 +1806,15 @@ unsafe extern "C" {
18061806
Subscripts: *const &'ll Metadata,
18071807
NumSubscripts: c_uint,
18081808
) -> &'ll Metadata;
1809+
1810+
pub(crate) fn LLVMDIBuilderCreateBasicType<'ll>(
1811+
Builder: &DIBuilder<'ll>,
1812+
Name: *const c_uchar,
1813+
NameLen: size_t,
1814+
SizeInBits: u64,
1815+
Encoding: c_uint, // `LLVMDWARFTypeEncoding`
1816+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1817+
) -> &'ll Metadata;
18091818
}
18101819

18111820
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2152,14 +2161,6 @@ unsafe extern "C" {
21522161
TParam: &'a DIArray,
21532162
) -> &'a DISubprogram;
21542163

2155-
pub(crate) fn LLVMRustDIBuilderCreateBasicType<'a>(
2156-
Builder: &DIBuilder<'a>,
2157-
Name: *const c_char,
2158-
NameLen: size_t,
2159-
SizeInBits: u64,
2160-
Encoding: c_uint,
2161-
) -> &'a DIBasicType;
2162-
21632164
pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
21642165
Builder: &DIBuilder<'a>,
21652166
Type: &'a DIBasicType,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1047,14 +1047,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod(
10471047
return wrap(Sub);
10481048
}
10491049

1050-
extern "C" LLVMMetadataRef
1051-
LLVMRustDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
1052-
size_t NameLen, uint64_t SizeInBits,
1053-
unsigned Encoding) {
1054-
return wrap(unwrap(Builder)->createBasicType(StringRef(Name, NameLen),
1055-
SizeInBits, Encoding));
1056-
}
1057-
10581050
extern "C" LLVMMetadataRef
10591051
LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
10601052
const char *Name, size_t NameLen,

0 commit comments

Comments
 (0)