Skip to content

Commit 3a5a8a5

Browse files
committed
Give variant parts their own unique id
and bump llvm version in test
1 parent e8de4c3 commit 3a5a8a5

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ impl TypeMap<'ll, 'tcx> {
188188
let interner_key = self.unique_id_interner.intern(&enum_variant_type_id);
189189
UniqueTypeId(interner_key)
190190
}
191+
192+
// Get the unique type id string for an enum variant part.
193+
// Variant parts are not types and shouldn't really have their own id,
194+
// but it makes set_members_of_composite_type() simpler.
195+
fn get_unique_type_id_str_of_enum_variant_part<'a>(&mut self,
196+
enum_type_id: UniqueTypeId) -> &str {
197+
let variant_part_type_id = format!("{}_variant_part",
198+
self.get_unique_type_id_as_string(enum_type_id));
199+
let interner_key = self.unique_id_interner.intern(&variant_part_type_id);
200+
self.unique_id_interner.get(interner_key)
201+
}
191202
}
192203

193204
// A description of some recursive type. It can either be already finished (as
@@ -266,7 +277,6 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
266277
// ... and attach them to the stub to complete it.
267278
set_members_of_composite_type(cx,
268279
unfinished_type,
269-
metadata_stub,
270280
member_holding_stub,
271281
member_descriptions);
272282
return MetadataCreationResult::new(metadata_stub, true);
@@ -1216,7 +1226,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12161226
set_members_of_composite_type(cx,
12171227
self.enum_type,
12181228
variant_type_metadata,
1219-
variant_type_metadata,
12201229
member_descriptions);
12211230
vec![
12221231
MemberDescription {
@@ -1258,7 +1267,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12581267
set_members_of_composite_type(cx,
12591268
self.enum_type,
12601269
variant_type_metadata,
1261-
variant_type_metadata,
12621270
member_descriptions);
12631271
MemberDescription {
12641272
name: if fallback {
@@ -1301,7 +1309,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13011309
set_members_of_composite_type(cx,
13021310
self.enum_type,
13031311
variant_type_metadata,
1304-
variant_type_metadata,
13051312
variant_member_descriptions);
13061313

13071314
// Encode the information about the null variant in the union
@@ -1362,7 +1369,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13621369
set_members_of_composite_type(cx,
13631370
self.enum_type,
13641371
variant_type_metadata,
1365-
variant_type_metadata,
13661372
member_descriptions);
13671373

13681374
let niche_value = if i == dataful_variant {
@@ -1691,6 +1697,11 @@ fn prepare_enum_metadata(
16911697
},
16921698
};
16931699

1700+
let variant_part_unique_type_id_str = SmallCStr::new(
1701+
debug_context(cx).type_map
1702+
.borrow_mut()
1703+
.get_unique_type_id_str_of_enum_variant_part(unique_type_id)
1704+
);
16941705
let empty_array = create_DIArray(DIB(cx), &[]);
16951706
let variant_part = unsafe {
16961707
llvm::LLVMRustDIBuilderCreateVariantPart(
@@ -1703,7 +1714,8 @@ fn prepare_enum_metadata(
17031714
layout.align.abi.bits() as u32,
17041715
DIFlags::FlagZero,
17051716
discriminator_metadata,
1706-
empty_array)
1717+
empty_array,
1718+
variant_part_unique_type_id_str.as_ptr())
17071719
};
17081720

17091721
// The variant part must be wrapped in a struct according to DWARF.
@@ -1774,16 +1786,14 @@ fn composite_type_metadata(
17741786
set_members_of_composite_type(cx,
17751787
composite_type,
17761788
composite_type_metadata,
1777-
composite_type_metadata,
17781789
member_descriptions);
17791790

17801791
composite_type_metadata
17811792
}
17821793

17831794
fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
17841795
composite_type: Ty<'tcx>,
1785-
metadata_stub: &'ll DICompositeType,
1786-
member_holding_stub: &'ll DICompositeType,
1796+
composite_type_metadata: &'ll DICompositeType,
17871797
member_descriptions: Vec<MemberDescription<'ll>>) {
17881798
// In some rare cases LLVM metadata uniquing would lead to an existing type
17891799
// description being used instead of a new one created in
@@ -1794,11 +1804,11 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
17941804
{
17951805
let mut composite_types_completed =
17961806
debug_context(cx).composite_types_completed.borrow_mut();
1797-
if composite_types_completed.contains(&metadata_stub) {
1807+
if composite_types_completed.contains(&composite_type_metadata) {
17981808
bug!("debuginfo::set_members_of_composite_type() - \
17991809
Already completed forward declaration re-encountered.");
18001810
} else {
1801-
composite_types_completed.insert(metadata_stub);
1811+
composite_types_completed.insert(composite_type_metadata);
18021812
}
18031813
}
18041814

@@ -1809,7 +1819,7 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
18091819
unsafe {
18101820
Some(llvm::LLVMRustDIBuilderCreateVariantMemberType(
18111821
DIB(cx),
1812-
member_holding_stub,
1822+
composite_type_metadata,
18131823
member_name.as_ptr(),
18141824
unknown_file_metadata(cx),
18151825
UNKNOWN_LINE_NUMBER,
@@ -1830,7 +1840,7 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
18301840
unsafe {
18311841
let type_array = create_DIArray(DIB(cx), &member_metadata[..]);
18321842
llvm::LLVMRustDICompositeTypeReplaceArrays(
1833-
DIB(cx), member_holding_stub, Some(type_array), type_params);
1843+
DIB(cx), composite_type_metadata, Some(type_array), type_params);
18341844
}
18351845
}
18361846

src/librustc_codegen_llvm/llvm/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,8 @@ extern "C" {
15871587
AlignInBits: u32,
15881588
Flags: DIFlags,
15891589
Discriminator: Option<&'a DIDerivedType>,
1590-
Elements: &'a DIArray)
1590+
Elements: &'a DIArray,
1591+
UniqueId: *const c_char)
15911592
-> &'a DIDerivedType;
15921593

15931594
pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);

src/rustllvm/RustWrapper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,12 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
723723
LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
724724
LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
725725
uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Discriminator,
726-
LLVMMetadataRef Elements) {
726+
LLVMMetadataRef Elements, const char *UniqueId) {
727727
#if LLVM_VERSION_GE(7, 0)
728728
return wrap(Builder->createVariantPart(
729729
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
730730
SizeInBits, AlignInBits, fromRust(Flags), unwrapDI<DIDerivedType>(Discriminator),
731-
DINodeArray(unwrapDI<MDTuple>(Elements))));
731+
DINodeArray(unwrapDI<MDTuple>(Elements)), UniqueId));
732732
#else
733733
abort();
734734
#endif

src/test/debuginfo/enum-thinlto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-tidy-linelength
22

33
// Require LLVM with DW_TAG_variant_part and a gdb that can read it.
4-
// min-system-llvm-version: 7.0
4+
// min-system-llvm-version: 8.0
55
// min-gdb-version: 8.2
66

77
// compile-flags:-g -Z thinlto

0 commit comments

Comments
 (0)