Skip to content

Commit d1ed8d4

Browse files
authored
Rollup merge of #146673 - Zalathar:di-builder, r=nnethercote
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 4) - Part of #134001 - Follow-up to #146631 --- This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs.
2 parents 540fd20 + 6b51f7c commit d1ed8d4

File tree

4 files changed

+103
-112
lines changed

4 files changed

+103
-112
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,14 +821,15 @@ fn build_basic_type_di_node<'ll, 'tcx>(
821821
};
822822

823823
let typedef_di_node = unsafe {
824-
llvm::LLVMRustDIBuilderCreateTypedef(
824+
llvm::LLVMDIBuilderCreateTypedef(
825825
DIB(cx),
826826
ty_di_node,
827-
typedef_name.as_c_char_ptr(),
827+
typedef_name.as_ptr(),
828828
typedef_name.len(),
829829
unknown_file_metadata(cx),
830-
0,
831-
None,
830+
0, // (no line number)
831+
None, // (no scope)
832+
0u32, // (no alignment specified)
832833
)
833834
};
834835

@@ -1034,10 +1035,10 @@ fn create_member_type<'ll, 'tcx>(
10341035
type_di_node: &'ll DIType,
10351036
) -> &'ll DIType {
10361037
unsafe {
1037-
llvm::LLVMRustDIBuilderCreateMemberType(
1038+
llvm::LLVMDIBuilderCreateMemberType(
10381039
DIB(cx),
10391040
owner,
1040-
name.as_c_char_ptr(),
1041+
name.as_ptr(),
10411042
name.len(),
10421043
file_metadata,
10431044
line_number,

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

Lines changed: 49 additions & 24 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

@@ -570,27 +567,28 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
570567
let build_assoc_const = |name: &str,
571568
type_di_node_: &'ll DIType,
572569
value: u64,
573-
align: Align| unsafe {
570+
align: Align|
571+
-> &'ll llvm::Metadata {
574572
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
575573
// problems inspecting other value types. Since DISCR_* is typically only going to be
576574
// directly inspected via the debugger visualizer - which compares it to the `tag` value
577575
// (whose type is not modified at all) it shouldn't cause any real problems.
578576
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
579-
(type_di_node_, align.bits() as u32)
577+
(type_di_node_, align)
580578
} else {
581579
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
582-
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
580+
(type_di_node(cx, ty_u64), Align::EIGHT)
583581
};
584582

585583
// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
586-
let field_type =
587-
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);
584+
let field_type = unsafe {
585+
llvm::LLVMDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di)
586+
};
588587

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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_target::spec::SymbolVisibility;
2424

2525
use super::RustString;
2626
use super::debuginfo::{
27-
DIArray, DIBasicType, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
27+
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
2828
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram, DISubrange,
2929
DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
3030
};
@@ -1943,6 +1943,52 @@ unsafe extern "C" {
19431943
UniqueId: *const c_uchar, // See "PTR_LEN_STR".
19441944
UniqueIdLen: size_t,
19451945
) -> &'ll Metadata;
1946+
1947+
pub(crate) fn LLVMDIBuilderCreateMemberType<'ll>(
1948+
Builder: &DIBuilder<'ll>,
1949+
Scope: &'ll Metadata,
1950+
Name: *const c_uchar, // See "PTR_LEN_STR".
1951+
NameLen: size_t,
1952+
File: &'ll Metadata,
1953+
LineNo: c_uint,
1954+
SizeInBits: u64,
1955+
AlignInBits: u32,
1956+
OffsetInBits: u64,
1957+
Flags: DIFlags,
1958+
Ty: &'ll Metadata,
1959+
) -> &'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;
1973+
1974+
/// Creates a "qualified type" in the C/C++ sense, by adding modifiers
1975+
/// like `const` or `volatile`.
1976+
pub(crate) fn LLVMDIBuilderCreateQualifiedType<'ll>(
1977+
Builder: &DIBuilder<'ll>,
1978+
Tag: c_uint, // (DWARF tag, e.g. `DW_TAG_const_type`)
1979+
Type: &'ll Metadata,
1980+
) -> &'ll Metadata;
1981+
1982+
pub(crate) fn LLVMDIBuilderCreateTypedef<'ll>(
1983+
Builder: &DIBuilder<'ll>,
1984+
Type: &'ll Metadata,
1985+
Name: *const c_uchar, // See "PTR_LEN_STR".
1986+
NameLen: size_t,
1987+
File: &'ll Metadata,
1988+
LineNo: c_uint,
1989+
Scope: Option<&'ll Metadata>,
1990+
AlignInBits: u32, // (optional; default is 0)
1991+
) -> &'ll Metadata;
19461992
}
19471993

19481994
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2278,30 +2324,6 @@ unsafe extern "C" {
22782324
TParam: &'a DIArray,
22792325
) -> &'a DISubprogram;
22802326

2281-
pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
2282-
Builder: &DIBuilder<'a>,
2283-
Type: &'a DIBasicType,
2284-
Name: *const c_char,
2285-
NameLen: size_t,
2286-
File: &'a DIFile,
2287-
LineNo: c_uint,
2288-
Scope: Option<&'a DIScope>,
2289-
) -> &'a DIDerivedType;
2290-
2291-
pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
2292-
Builder: &DIBuilder<'a>,
2293-
Scope: &'a DIDescriptor,
2294-
Name: *const c_char,
2295-
NameLen: size_t,
2296-
File: &'a DIFile,
2297-
LineNo: c_uint,
2298-
SizeInBits: u64,
2299-
AlignInBits: u32,
2300-
OffsetInBits: u64,
2301-
Flags: DIFlags,
2302-
Ty: &'a DIType,
2303-
) -> &'a DIDerivedType;
2304-
23052327
pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
23062328
Builder: &DIBuilder<'a>,
23072329
Scope: &'a DIScope,
@@ -2317,25 +2339,6 @@ unsafe extern "C" {
23172339
Ty: &'a DIType,
23182340
) -> &'a DIType;
23192341

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-
2333-
pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
2334-
Builder: &DIBuilder<'a>,
2335-
Tag: c_uint,
2336-
Type: &'a DIType,
2337-
) -> &'a DIDerivedType;
2338-
23392342
pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
23402343
Builder: &DIBuilder<'a>,
23412344
Context: Option<&'a DIScope>,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,16 +1064,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod(
10641064
return wrap(Sub);
10651065
}
10661066

1067-
extern "C" LLVMMetadataRef
1068-
LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
1069-
const char *Name, size_t NameLen,
1070-
LLVMMetadataRef File, unsigned LineNo,
1071-
LLVMMetadataRef Scope) {
1072-
return wrap(unwrap(Builder)->createTypedef(
1073-
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
1074-
LineNo, unwrapDIPtr<DIScope>(Scope)));
1075-
}
1076-
10771067
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
10781068
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
10791069
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
@@ -1088,17 +1078,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
10881078
StringRef(UniqueId, UniqueIdLen)));
10891079
}
10901080

1091-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMemberType(
1092-
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1093-
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
1094-
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
1095-
LLVMMetadataRef Ty) {
1096-
return wrap(unwrap(Builder)->createMemberType(
1097-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1098-
unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, OffsetInBits,
1099-
fromRust(Flags), unwrapDI<DIType>(Ty)));
1100-
}
1101-
11021081
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
11031082
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
11041083
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
@@ -1114,23 +1093,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
11141093
fromRust(Flags), unwrapDI<DIType>(Ty)));
11151094
}
11161095

1117-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
1118-
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1119-
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
1120-
LLVMDIFlags Flags, LLVMValueRef val, uint32_t AlignInBits) {
1121-
return wrap(unwrap(Builder)->createStaticMemberType(
1122-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1123-
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), fromRust(Flags),
1124-
unwrap<llvm::ConstantInt>(val), llvm::dwarf::DW_TAG_member, AlignInBits));
1125-
}
1126-
1127-
extern "C" LLVMMetadataRef
1128-
LLVMRustDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
1129-
LLVMMetadataRef Type) {
1130-
return wrap(
1131-
unwrap(Builder)->createQualifiedType(Tag, unwrapDI<DIType>(Type)));
1132-
}
1133-
11341096
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
11351097
LLVMDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name,
11361098
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,

0 commit comments

Comments
 (0)