From edafeb956c7b46228f8222851e72ad2126edab24 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sun, 24 Apr 2016 06:52:01 +0000 Subject: [PATCH] BitcodeReader: Fix some holes in upgrade from r267296 Add tests for some missing cases to bitcode upgrade in r267296. - DICompositeType with an 'elements:' field, which will cause it to be involved in a cycle after the upgrade. - A DIDerivedType that references a class in 'extraData:'. I updated test/Bitcode/dityperefs-3.8.ll with the missing cases and regenerated test/Bitcode/dityperefs-3.8.ll.bc. llvm-svn: 267332 --- lib/Bitcode/Reader/BitcodeReader.cpp | 30 ++++++++++++++++++++------- test/Bitcode/dityperefs-3.8.ll | 10 ++++++++- test/Bitcode/dityperefs-3.8.ll.bc | Bin 840 -> 888 bytes 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index b8db3e8feea..7dbf4e64cf2 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1158,6 +1158,8 @@ void BitcodeReaderMetadataList::tryToResolveCycles() { // Still forward references... can't resolve cycles. return; + bool DidReplaceTypeRefs = false; + // Give up on finding a full definition for any forward decls that remain. for (const auto &Ref : OldTypeRefs.FwdDecls) OldTypeRefs.Final.insert(Ref); @@ -1165,19 +1167,31 @@ void BitcodeReaderMetadataList::tryToResolveCycles() { // Upgrade from old type ref arrays. In strange cases, this could add to // OldTypeRefs.Unknown. - for (const auto &Array : OldTypeRefs.Arrays) + for (const auto &Array : OldTypeRefs.Arrays) { + DidReplaceTypeRefs = true; Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get())); + } + OldTypeRefs.Arrays.clear(); // Replace old string-based type refs with the resolved node, if possible. // If we haven't seen the node, leave it to the verifier to complain about // the invalid string reference. - for (const auto &Ref : OldTypeRefs.Unknown) + for (const auto &Ref : OldTypeRefs.Unknown) { + DidReplaceTypeRefs = true; if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first)) Ref.second->replaceAllUsesWith(CT); else Ref.second->replaceAllUsesWith(Ref.first); + } OldTypeRefs.Unknown.clear(); + // Make sure all the upgraded types are resolved. + if (DidReplaceTypeRefs) { + AnyFwdRefs = true; + MinFwdRef = 0; + MaxFwdRef = MetadataPtrs.size() - 1; + } + if (!AnyFwdRefs) // Nothing to do. return; @@ -2346,12 +2360,12 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { IsDistinct = Record[0]; MetadataList.assignValue( - GET_OR_DISTINCT(DIDerivedType, - (Context, Record[1], getMDString(Record[2]), - getMDOrNull(Record[3]), Record[4], - getDITypeRefOrNull(Record[5]), - getDITypeRefOrNull(Record[6]), Record[7], Record[8], - Record[9], Record[10], getMDOrNull(Record[11]))), + GET_OR_DISTINCT( + DIDerivedType, + (Context, Record[1], getMDString(Record[2]), + getMDOrNull(Record[3]), Record[4], getDITypeRefOrNull(Record[5]), + getDITypeRefOrNull(Record[6]), Record[7], Record[8], Record[9], + Record[10], getDITypeRefOrNull(Record[11]))), NextMetadataNo++); break; } diff --git a/test/Bitcode/dityperefs-3.8.ll b/test/Bitcode/dityperefs-3.8.ll index 4025f21f0cd..6c953f28aba 100644 --- a/test/Bitcode/dityperefs-3.8.ll +++ b/test/Bitcode/dityperefs-3.8.ll @@ -2,7 +2,7 @@ ; RUN: verify-uselistorder %s.bc ; Establish a stable order. -!named = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12} +!named = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16} ; CHECK: !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir") ; CHECK-NEXT: !1 = !DICompositeType(tag: DW_TAG_structure_type, name: "T1"{{.*}}, identifier: "T1") @@ -17,6 +17,10 @@ ; CHECK-NEXT: !10 = !DIGlobalVariable(name: "G",{{.*}} type: !1,{{.*}} variable: i32* @G1) ; CHECK-NEXT: !11 = !DITemplateValueParameter(type: !1, value: i32* @G1) ; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "T2", scope: !0, entity: !1) +; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "T3", file: !0, elements: !14, identifier: "T3") +; CHECK-NEXT: !14 = !{!15} +; CHECK-NEXT: !15 = !DISubprogram(scope: !13, +; CHECK-NEXT: !16 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type,{{.*}} extraData: !13) !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir") !1 = !DICompositeType(tag: DW_TAG_structure_type, name: "T1", file: !0, identifier: "T1") @@ -31,5 +35,9 @@ !10 = !DIGlobalVariable(name: "G", type: !"T1", isDefinition: false, variable: i32* @G1) !11 = !DITemplateValueParameter(type: !"T1", value: i32* @G1) !12 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "T2", scope: !0, entity: !"T1") +!13 = !DICompositeType(tag: DW_TAG_structure_type, name: "T3", file: !0, elements: !14, identifier: "T3") +!14 = !{!15} +!15 = !DISubprogram(scope: !"T3", isDefinition: false) +!16 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !4, extraData: !"T3") @G1 = global i32 0 diff --git a/test/Bitcode/dityperefs-3.8.ll.bc b/test/Bitcode/dityperefs-3.8.ll.bc index 0808389c7c567152b06b43b2c6b0cee788e1c58a..4ec0bca70fa4dce5c6416e3cd9adbb60f323bf8a 100644 GIT binary patch delta 98 zcmX@X_JeJL3geZDsq!s5u@e;RTDN rFfhb)OFUp^V2A+n*NNpN=BB0uD>NDiq-M%xELz30+hp@1#$}8EH7Fi3 delta 50 zcmV-20L}mS2FM1GBmu~gC7K47#0G)F$&tk)0WOj0rxGpP!rIEnrZ56wAj;A_&_q=L Iv(f>k0Z7ai