Skip to content

Commit 331692d

Browse files
committed
Use LLVMDIBuilderCreateBasicType
1 parent f4f8663 commit 331692d

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

@@ -769,15 +765,7 @@ fn build_basic_type_di_node<'ll, 'tcx>(
769765
_ => bug!("debuginfo::build_basic_type_di_node - `t` is invalid type"),
770766
};
771767

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

782770
if !cpp_like_debuginfo {
783771
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
@@ -1804,6 +1804,15 @@ unsafe extern "C" {
18041804
Subscripts: *const &'ll Metadata,
18051805
NumSubscripts: c_uint,
18061806
) -> &'ll Metadata;
1807+
1808+
pub(crate) fn LLVMDIBuilderCreateBasicType<'ll>(
1809+
Builder: &DIBuilder<'ll>,
1810+
Name: *const c_uchar,
1811+
NameLen: size_t,
1812+
SizeInBits: u64,
1813+
Encoding: c_uint, // `LLVMDWARFTypeEncoding`
1814+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1815+
) -> &'ll Metadata;
18071816
}
18081817

18091818
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2150,14 +2159,6 @@ unsafe extern "C" {
21502159
TParam: &'a DIArray,
21512160
) -> &'a DISubprogram;
21522161

2153-
pub(crate) fn LLVMRustDIBuilderCreateBasicType<'a>(
2154-
Builder: &DIBuilder<'a>,
2155-
Name: *const c_char,
2156-
NameLen: size_t,
2157-
SizeInBits: u64,
2158-
Encoding: c_uint,
2159-
) -> &'a DIBasicType;
2160-
21612162
pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
21622163
Builder: &DIBuilder<'a>,
21632164
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)