Skip to content

Commit bb21dbe

Browse files
committed
Use LLVMDIBuilderCreateStaticMemberType
1 parent 923d1be commit bb21dbe

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1111
use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty};
1212
use smallvec::smallvec;
1313

14-
use crate::common::{AsCCharPtr, CodegenCx};
14+
use crate::common::CodegenCx;
1515
use crate::debuginfo::dwarf_const::DW_TAG_const_type;
1616
use crate::debuginfo::metadata::enums::DiscrResult;
1717
use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId};
@@ -378,20 +378,17 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
378378
variant_struct_type_wrapper_di_node,
379379
None,
380380
),
381-
unsafe {
382-
llvm::LLVMRustDIBuilderCreateStaticMemberType(
383-
DIB(cx),
384-
enum_type_di_node,
385-
TAG_FIELD_NAME.as_c_char_ptr(),
386-
TAG_FIELD_NAME.len(),
387-
unknown_file_metadata(cx),
388-
UNKNOWN_LINE_NUMBER,
389-
variant_names_type_di_node,
390-
visibility_flags,
391-
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
392-
tag_base_type_align.bits() as u32,
393-
)
394-
}
381+
create_static_member_type(
382+
cx,
383+
enum_type_di_node,
384+
TAG_FIELD_NAME,
385+
unknown_file_metadata(cx),
386+
UNKNOWN_LINE_NUMBER,
387+
variant_names_type_di_node,
388+
visibility_flags,
389+
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
390+
tag_base_type_align,
391+
),
395392
]
396393
}
397394

@@ -576,21 +573,20 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
576573
// directly inspected via the debugger visualizer - which compares it to the `tag` value
577574
// (whose type is not modified at all) it shouldn't cause any real problems.
578575
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
579-
(type_di_node_, align.bits() as u32)
576+
(type_di_node_, align)
580577
} else {
581578
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
582-
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
579+
(type_di_node(cx, ty_u64), Align::EIGHT)
583580
};
584581

585582
// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
586583
let field_type =
587584
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);
588585

589-
llvm::LLVMRustDIBuilderCreateStaticMemberType(
590-
DIB(cx),
586+
create_static_member_type(
587+
cx,
591588
wrapper_struct_type_di_node,
592-
name.as_c_char_ptr(),
593-
name.len(),
589+
name,
594590
unknown_file_metadata(cx),
595591
UNKNOWN_LINE_NUMBER,
596592
field_type,
@@ -975,3 +971,30 @@ fn variant_struct_wrapper_type_name(variant_index: VariantIdx) -> Cow<'static, s
975971
.map(|&s| Cow::from(s))
976972
.unwrap_or_else(|| format!("Variant{}", variant_index.as_usize()).into())
977973
}
974+
975+
fn create_static_member_type<'ll>(
976+
cx: &CodegenCx<'ll, '_>,
977+
scope: &'ll llvm::Metadata,
978+
name: &str,
979+
file: &'ll llvm::Metadata,
980+
line_number: c_uint,
981+
ty: &'ll llvm::Metadata,
982+
flags: DIFlags,
983+
value: Option<&'ll llvm::Value>,
984+
align: Align,
985+
) -> &'ll llvm::Metadata {
986+
unsafe {
987+
llvm::LLVMDIBuilderCreateStaticMemberType(
988+
DIB(cx),
989+
scope,
990+
name.as_ptr(),
991+
name.len(),
992+
file,
993+
line_number,
994+
ty,
995+
flags,
996+
value,
997+
align.bits() as c_uint,
998+
)
999+
}
1000+
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,19 @@ unsafe extern "C" {
19571957
Flags: DIFlags,
19581958
Ty: &'ll Metadata,
19591959
) -> &'ll Metadata;
1960+
1961+
pub(crate) fn LLVMDIBuilderCreateStaticMemberType<'ll>(
1962+
Builder: &DIBuilder<'ll>,
1963+
Scope: &'ll Metadata,
1964+
Name: *const c_uchar, // See "PTR_LEN_STR".
1965+
NameLen: size_t,
1966+
File: &'ll Metadata,
1967+
LineNumber: c_uint,
1968+
Type: &'ll Metadata,
1969+
Flags: DIFlags,
1970+
ConstantVal: Option<&'ll Value>,
1971+
AlignInBits: u32,
1972+
) -> &'ll Metadata;
19601973
}
19611974

19621975
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2317,19 +2330,6 @@ unsafe extern "C" {
23172330
Ty: &'a DIType,
23182331
) -> &'a DIType;
23192332

2320-
pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
2321-
Builder: &DIBuilder<'a>,
2322-
Scope: &'a DIDescriptor,
2323-
Name: *const c_char,
2324-
NameLen: size_t,
2325-
File: &'a DIFile,
2326-
LineNo: c_uint,
2327-
Ty: &'a DIType,
2328-
Flags: DIFlags,
2329-
val: Option<&'a Value>,
2330-
AlignInBits: u32,
2331-
) -> &'a DIDerivedType;
2332-
23332333
pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
23342334
Builder: &DIBuilder<'a>,
23352335
Tag: c_uint,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,16 +1103,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
11031103
fromRust(Flags), unwrapDI<DIType>(Ty)));
11041104
}
11051105

1106-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
1107-
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1108-
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1109-
LLVMDIFlags Flags, LLVMValueRef val, uint32_t AlignInBits) {
1110-
return wrap(unwrap(Builder)->createStaticMemberType(
1111-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1112-
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), fromRust(Flags),
1113-
unwrap<llvm::ConstantInt>(val), llvm::dwarf::DW_TAG_member, AlignInBits));
1114-
}
1115-
11161106
extern "C" LLVMMetadataRef
11171107
LLVMRustDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
11181108
LLVMMetadataRef Type) {

0 commit comments

Comments
 (0)