[llvm] r257000 - Always treat DISubprogram reached by DIImportedEntity as needed.

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 16:06:27 PST 2016


Author: tejohnson
Date: Wed Jan  6 18:06:27 2016
New Revision: 257000

URL: http://llvm.org/viewvc/llvm-project?rev=257000&view=rev
Log:
Always treat DISubprogram reached by DIImportedEntity as needed.

It is illegal to have a null entity in a DIImportedEntity, so
we must link in a DISubprogram metadata node referenced by one,
even if the associated function is not linked in or inlined anywhere.

Fixes PR26037.

Added:
    llvm/trunk/test/Linker/Inputs/pr26037.ll
    llvm/trunk/test/Linker/pr26037.ll
Modified:
    llvm/trunk/lib/Linker/IRMover.cpp

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=257000&r1=256999&r2=257000&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Wed Jan  6 18:06:27 2016
@@ -1211,6 +1211,16 @@ void IRLinker::findNeededSubprograms(Val
   for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
     auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I));
     assert(CU && "Expected valid compile unit");
+    // Ensure that we don't remove subprograms referenced by DIImportedEntity.
+    // It is not legal to have a DIImportedEntity with a null entity.
+    // FIXME: The DISubprogram for functions not linked in but kept due to
+    // being referenced by a DIImportedEntity should also get their
+    // IsDefinition flag is unset.
+    SmallPtrSet<DISubprogram *, 8> ImportedEntitySPs;
+    for (auto *IE : CU->getImportedEntities()) {
+      if (auto *SP = dyn_cast<DISubprogram>(IE->getEntity()))
+        ImportedEntitySPs.insert(SP);
+    }
     for (auto *Op : CU->getSubprograms()) {
       // Unless we were doing function importing and deferred metadata linking,
       // any needed SPs should have been mapped as they would be reached
@@ -1218,7 +1228,7 @@ void IRLinker::findNeededSubprograms(Val
       // function bodies, or from DILocation on inlined instructions).
       assert(!(ValueMap.MD()[Op] && IsMetadataLinkingPostpass) &&
              "DISubprogram shouldn't be mapped yet");
-      if (!ValueMap.MD()[Op])
+      if (!ValueMap.MD()[Op] && !ImportedEntitySPs.count(Op))
         UnneededSubprograms.insert(Op);
     }
   }

Added: llvm/trunk/test/Linker/Inputs/pr26037.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/pr26037.ll?rev=257000&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/pr26037.ll (added)
+++ llvm/trunk/test/Linker/Inputs/pr26037.ll Wed Jan  6 18:06:27 2016
@@ -0,0 +1,23 @@
+define i32 @main() #0 !dbg !4 {
+entry:
+  %retval = alloca i32, align 4
+  store i32 0, i32* %retval, align 4
+  ret i32 0, !dbg !11
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9}
+!llvm.ident = !{!10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 256934) (llvm/trunk 256936)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
+!1 = !DIFile(filename: "main.cc", directory: "")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!8 = !{i32 2, !"Dwarf Version", i32 4}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{!"clang version 3.8.0 (trunk 256934) (llvm/trunk 256936)"}
+!11 = !DILocation(line: 1, column: 14, scope: !4)

Added: llvm/trunk/test/Linker/pr26037.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/pr26037.ll?rev=257000&view=auto
==============================================================================
--- llvm/trunk/test/Linker/pr26037.ll (added)
+++ llvm/trunk/test/Linker/pr26037.ll Wed Jan  6 18:06:27 2016
@@ -0,0 +1,30 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-as %p/Inputs/pr26037.ll -o %t2.bc
+; RUN: llvm-link -S -only-needed %t2.bc %t.bc | FileCheck %s
+
+; CHECK: distinct !DISubprogram(name: "a"
+; CHECK: !DIImportedEntity({{.*}}, entity:
+
+define void @_ZN1A1aEv() #0 !dbg !4 {
+entry:
+  ret void, !dbg !13
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!10, !11}
+!llvm.ident = !{!12}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 256934) (llvm/trunk 256936)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, imports: !8)
+!1 = !DIFile(filename: "a2.cc", directory: "")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "a", linkageName: "_ZN1A1aEv", scope: !5, file: !1, line: 5, type: !6, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
+!5 = !DINamespace(name: "A", scope: null, file: !1, line: 1)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{!9}
+!9 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !4, line: 2)
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{!"clang version 3.8.0 (trunk 256934) (llvm/trunk 256936)"}
+!13 = !DILocation(line: 6, column: 1, scope: !4)




More information about the llvm-commits mailing list