Handle empty Subprogram list when linking metadata.
authorTeresa Johnson <tejohnson@google.com>
Tue, 22 Dec 2015 01:17:19 +0000 (01:17 +0000)
committerTeresa Johnson <tejohnson@google.com>
Tue, 22 Dec 2015 01:17:19 +0000 (01:17 +0000)
Use an iterator that handles an empty subprogram list.

Fixes PR25915.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256224 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/IRMover.cpp
test/tools/gold/X86/pr25915.ll [new file with mode: 0644]

index 6e344f81b5fdfc9d7dc6fce17eeabb5c20df0d20..4a31c4a1a977e9aa26e7ee7a0c70b121a806883e 100644 (file)
@@ -1193,7 +1193,7 @@ void IRLinker::findNeededSubprograms(ValueToValueMapTy &ValueMap) {
   for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
     auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I));
     assert(CU && "Expected valid compile unit");
-    for (const Metadata *Op : CU->getSubprograms()->operands()) {
+    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
       // from the function linked in (either on the function itself for linked
diff --git a/test/tools/gold/X86/pr25915.ll b/test/tools/gold/X86/pr25915.ll
new file mode 100644 (file)
index 0000000..2d8807e
--- /dev/null
@@ -0,0 +1,17 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:    -plugin-opt=emit-llvm \
+; RUN:    -shared %t.o -o %t2
+; RUN: llvm-dis %t2 -o - | FileCheck %s
+; CHECK-NOT: subprograms
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 256170) (llvm/trunk 256171)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "pr25915.cc", directory: ".")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{!"clang version 3.8.0 (trunk 256170) (llvm/trunk 256171)"}