Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Give variant parts their own unique id
and bump llvm version in test
  • Loading branch information
philipc committed Mar 27, 2019
commit 3a5a8a529a14271f5d8c21bec8746edfa93eec5f
36 changes: 23 additions & 13 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ impl TypeMap<'ll, 'tcx> {
let interner_key = self.unique_id_interner.intern(&enum_variant_type_id);
UniqueTypeId(interner_key)
}

// Get the unique type id string for an enum variant part.
// Variant parts are not types and shouldn't really have their own id,
// but it makes set_members_of_composite_type() simpler.
fn get_unique_type_id_str_of_enum_variant_part<'a>(&mut self,
enum_type_id: UniqueTypeId) -> &str {
let variant_part_type_id = format!("{}_variant_part",
self.get_unique_type_id_as_string(enum_type_id));
let interner_key = self.unique_id_interner.intern(&variant_part_type_id);
self.unique_id_interner.get(interner_key)
}
}

// A description of some recursive type. It can either be already finished (as
Expand Down Expand Up @@ -266,7 +277,6 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
// ... and attach them to the stub to complete it.
set_members_of_composite_type(cx,
unfinished_type,
metadata_stub,
member_holding_stub,
member_descriptions);
return MetadataCreationResult::new(metadata_stub, true);
Expand Down Expand Up @@ -1216,7 +1226,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
set_members_of_composite_type(cx,
self.enum_type,
variant_type_metadata,
variant_type_metadata,
member_descriptions);
vec![
MemberDescription {
Expand Down Expand Up @@ -1258,7 +1267,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
set_members_of_composite_type(cx,
self.enum_type,
variant_type_metadata,
variant_type_metadata,
member_descriptions);
MemberDescription {
name: if fallback {
Expand Down Expand Up @@ -1301,7 +1309,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
set_members_of_composite_type(cx,
self.enum_type,
variant_type_metadata,
variant_type_metadata,
variant_member_descriptions);

// Encode the information about the null variant in the union
Expand Down Expand Up @@ -1362,7 +1369,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
set_members_of_composite_type(cx,
self.enum_type,
variant_type_metadata,
variant_type_metadata,
member_descriptions);

let niche_value = if i == dataful_variant {
Expand Down Expand Up @@ -1691,6 +1697,11 @@ fn prepare_enum_metadata(
},
};

let variant_part_unique_type_id_str = SmallCStr::new(
debug_context(cx).type_map
.borrow_mut()
.get_unique_type_id_str_of_enum_variant_part(unique_type_id)
);
let empty_array = create_DIArray(DIB(cx), &[]);
let variant_part = unsafe {
llvm::LLVMRustDIBuilderCreateVariantPart(
Expand All @@ -1703,7 +1714,8 @@ fn prepare_enum_metadata(
layout.align.abi.bits() as u32,
DIFlags::FlagZero,
discriminator_metadata,
empty_array)
empty_array,
variant_part_unique_type_id_str.as_ptr())
};

// The variant part must be wrapped in a struct according to DWARF.
Expand Down Expand Up @@ -1774,16 +1786,14 @@ fn composite_type_metadata(
set_members_of_composite_type(cx,
composite_type,
composite_type_metadata,
composite_type_metadata,
member_descriptions);

composite_type_metadata
}

fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
composite_type: Ty<'tcx>,
metadata_stub: &'ll DICompositeType,
member_holding_stub: &'ll DICompositeType,
composite_type_metadata: &'ll DICompositeType,
member_descriptions: Vec<MemberDescription<'ll>>) {
// In some rare cases LLVM metadata uniquing would lead to an existing type
// description being used instead of a new one created in
Expand All @@ -1794,11 +1804,11 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
{
let mut composite_types_completed =
debug_context(cx).composite_types_completed.borrow_mut();
if composite_types_completed.contains(&metadata_stub) {
if composite_types_completed.contains(&composite_type_metadata) {
bug!("debuginfo::set_members_of_composite_type() - \
Already completed forward declaration re-encountered.");
} else {
composite_types_completed.insert(metadata_stub);
composite_types_completed.insert(composite_type_metadata);
}
}

Expand All @@ -1809,7 +1819,7 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
unsafe {
Some(llvm::LLVMRustDIBuilderCreateVariantMemberType(
DIB(cx),
member_holding_stub,
composite_type_metadata,
member_name.as_ptr(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
Expand All @@ -1830,7 +1840,7 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
unsafe {
let type_array = create_DIArray(DIB(cx), &member_metadata[..]);
llvm::LLVMRustDICompositeTypeReplaceArrays(
DIB(cx), member_holding_stub, Some(type_array), type_params);
DIB(cx), composite_type_metadata, Some(type_array), type_params);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,8 @@ extern "C" {
AlignInBits: u32,
Flags: DIFlags,
Discriminator: Option<&'a DIDerivedType>,
Elements: &'a DIArray)
Elements: &'a DIArray,
UniqueId: *const c_char)
-> &'a DIDerivedType;

pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
Expand Down
4 changes: 2 additions & 2 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,12 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Discriminator,
LLVMMetadataRef Elements) {
LLVMMetadataRef Elements, const char *UniqueId) {
#if LLVM_VERSION_GE(7, 0)
return wrap(Builder->createVariantPart(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
SizeInBits, AlignInBits, fromRust(Flags), unwrapDI<DIDerivedType>(Discriminator),
DINodeArray(unwrapDI<MDTuple>(Elements))));
DINodeArray(unwrapDI<MDTuple>(Elements)), UniqueId));
#else
abort();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/test/debuginfo/enum-thinlto.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-tidy-linelength

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

// compile-flags:-g -Z thinlto
Expand Down