about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/debuginfo
diff options
context:
space:
mode:
authorPhilip Craig <philipjcraig@gmail.com>2019-03-23 17:00:04 +1000
committerPhilip Craig <philipjcraig@gmail.com>2019-03-23 17:13:58 +1000
commite8de4c3b1f0ab51fe3ea0a494cf9727ee3e0bf1d (patch)
treec9b2d4d2a1b8012e37c9092919d8a091af9bdffa /src/librustc_codegen_llvm/debuginfo
parentc82834e2b930619d4143e4dd94fb80888fa190c9 (diff)
downloadrust-e8de4c3b1f0ab51fe3ea0a494cf9727ee3e0bf1d.tar.gz
rust-e8de4c3b1f0ab51fe3ea0a494cf9727ee3e0bf1d.zip
Fix invalid DWARF for enums when using thinlto
We were setting the same identifier for both the DW_TAG_structure_type
and the DW_TAG_variant_part. This becomes a problem when using thinlto
becauses it uses the identifier as a key for a map of types that is used
to delete duplicates based on the ODR, so one of them is deleted as a
duplicate, resulting in invalid DWARF.

The DW_TAG_variant_part isn't a standalone type, so it doesn't need
an identifier. Fix by omitting its identifier.
Diffstat (limited to 'src/librustc_codegen_llvm/debuginfo')
-rw-r--r--src/librustc_codegen_llvm/debuginfo/metadata.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs
index ddcbf29da83..1859b1f4792 100644
--- a/src/librustc_codegen_llvm/debuginfo/metadata.rs
+++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs
@@ -266,6 +266,7 @@ 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);
@@ -1215,6 +1216,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
                 set_members_of_composite_type(cx,
                                               self.enum_type,
                                               variant_type_metadata,
+                                              variant_type_metadata,
                                               member_descriptions);
                 vec![
                     MemberDescription {
@@ -1256,6 +1258,7 @@ 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 {
@@ -1298,6 +1301,7 @@ 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
@@ -1358,6 +1362,7 @@ 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 {
@@ -1698,8 +1703,7 @@ fn prepare_enum_metadata(
             layout.align.abi.bits() as u32,
             DIFlags::FlagZero,
             discriminator_metadata,
-            empty_array,
-            unique_type_id_str.as_ptr())
+            empty_array)
     };
 
     // The variant part must be wrapped in a struct according to DWARF.
@@ -1770,6 +1774,7 @@ fn composite_type_metadata(
     set_members_of_composite_type(cx,
                                   composite_type,
                                   composite_type_metadata,
+                                  composite_type_metadata,
                                   member_descriptions);
 
     composite_type_metadata
@@ -1777,7 +1782,8 @@ fn composite_type_metadata(
 
 fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
                                  composite_type: Ty<'tcx>,
-                                 composite_type_metadata: &'ll DICompositeType,
+                                 metadata_stub: &'ll DICompositeType,
+                                 member_holding_stub: &'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
@@ -1788,11 +1794,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(&composite_type_metadata) {
+        if composite_types_completed.contains(&metadata_stub) {
             bug!("debuginfo::set_members_of_composite_type() - \
                   Already completed forward declaration re-encountered.");
         } else {
-            composite_types_completed.insert(composite_type_metadata);
+            composite_types_completed.insert(metadata_stub);
         }
     }
 
@@ -1803,7 +1809,7 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
             unsafe {
                 Some(llvm::LLVMRustDIBuilderCreateVariantMemberType(
                     DIB(cx),
-                    composite_type_metadata,
+                    member_holding_stub,
                     member_name.as_ptr(),
                     unknown_file_metadata(cx),
                     UNKNOWN_LINE_NUMBER,
@@ -1824,7 +1830,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), composite_type_metadata, Some(type_array), type_params);
+            DIB(cx), member_holding_stub, Some(type_array), type_params);
     }
 }