summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-09-03 21:12:33 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-09-03 21:12:33 +0000
commitebb34348500aa8dd93125e71e36da779339d89a1 (patch)
tree1b876c337d54ea9cafc65b72315d28d5ed188a78
parent3606d2346cccfb4f6dbb5f7903eeb11ebc151c25 (diff)
downloadbcm5719-llvm-ebb34348500aa8dd93125e71e36da779339d89a1.tar.gz
bcm5719-llvm-ebb34348500aa8dd93125e71e36da779339d89a1.zip
Fix ThinLTO crash with debug info
Because the recent change about ODR type uniquing in the context, we can reach types defined in another module during IR linking. This triggered some assertions in case we IR link without starting from an empty module. To alleviate that, we can self-map metadata defined in the destination module so that they won't be visited. Differential Revision: https://reviews.llvm.org/D23841 llvm-svn: 280599
-rw-r--r--llvm/include/llvm/IR/TypeFinder.h2
-rw-r--r--llvm/lib/Linker/IRMover.cpp6
-rw-r--r--llvm/test/ThinLTO/X86/Inputs/crash_debuginfo.ll33
-rw-r--r--llvm/test/ThinLTO/X86/crash_debuginfo.ll46
4 files changed, 87 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/TypeFinder.h b/llvm/include/llvm/IR/TypeFinder.h
index d5baf7ab0b9..046f85caec9 100644
--- a/llvm/include/llvm/IR/TypeFinder.h
+++ b/llvm/include/llvm/IR/TypeFinder.h
@@ -59,6 +59,8 @@ public:
StructType *&operator[](unsigned Idx) { return StructTypes[Idx]; }
+ DenseSet<const MDNode *> &getVisitedMetadata() { return VisitedMetadata; }
+
private:
/// incorporateType - This method adds the type to the list of used
/// structures if it's not in there already.
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 6def096ccd7..c02abd7e3ac 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1342,6 +1342,12 @@ IRMover::IRMover(Module &M) : Composite(M) {
else
IdentifiedStructTypes.addNonOpaque(Ty);
}
+ // Self-map metadatas in the destination module. This is needed when
+ // DebugTypeODRUniquing is enabled on the LLVMContext, since metadata in the
+ // destination module may be reached from the source module.
+ for (auto *MD : StructTypes.getVisitedMetadata()) {
+ SharedMDs[MD].reset(const_cast<MDNode *>(MD));
+ }
}
Error IRMover::move(
diff --git a/llvm/test/ThinLTO/X86/Inputs/crash_debuginfo.ll b/llvm/test/ThinLTO/X86/Inputs/crash_debuginfo.ll
new file mode 100644
index 00000000000..9bb9a2fb0c5
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/Inputs/crash_debuginfo.ll
@@ -0,0 +1,33 @@
+; ModuleID = 'test/ThinLTO/X86/Inputs/crash_debuginfo.ll'
+source_filename = "src.bc"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.7.0"
+
+%another_type = type { i32 }
+
+define void @bar(i32 %arg) {
+ %tmp = add i32 %arg, 0, !dbg !7
+ unreachable
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "Apple LLVM version 8.0.0 (clang-800.0.25.1)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3, imports: !2)
+!1 = !DIFile(filename: "2.cpp", directory: "some_dir")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DIGlobalVariable(name: "a_global", linkageName: "a_global", scope: null, line: 52, type: !5, isLocal: true, isDefinition: true, variable: %another_type** undef)
+!5 = !DISubroutineType(types: !2)
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = distinct !DILocation(line: 728, column: 71, scope: !8, inlinedAt: !14)
+!8 = distinct !DISubprogram(name: "baz", linkageName: "baz", scope: !9, file: !1, line: 726, type: !5, isLocal: false, isDefinition: true, scopeLine: 727, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !10, variables: !11)
+!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "some_other_class", scope: !1, file: !1, line: 197, size: 192, align: 64, elements: !2, templateParams: !2, identifier: "some_other_class")
+!10 = !DISubprogram(name: "baz", linkageName: "baz", scope: !9, file: !1, line: 726, type: !5, isLocal: false, isDefinition: false, scopeLine: 726, flags: DIFlagPrototyped, isOptimized: true)
+!11 = !{!12}
+!12 = !DILocalVariable(name: "caster", scope: !8, file: !1, line: 728, type: !13)
+!13 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !8, file: !1, line: 728, size: 64, align: 64, elements: !2, identifier: "someclass")
+!14 = distinct !DILocation(line: 795, column: 16, scope: !15)
+!15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 794, column: 7)
+!16 = distinct !DISubprogram(name: "operator()", linkageName: "some_special_function", scope: null, file: !1, line: 783, type: !5, isLocal: true, isDefinition: true, scopeLine: 784, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !17, variables: !2)
+!17 = !DISubprogram(name: "operator()", linkageName: "some_special_function", scope: null, file: !1, line: 783, type: !5, isLocal: false, isDefinition: false, scopeLine: 783, flags: DIFlagPrototyped, isOptimized: true)
diff --git a/llvm/test/ThinLTO/X86/crash_debuginfo.ll b/llvm/test/ThinLTO/X86/crash_debuginfo.ll
new file mode 100644
index 00000000000..b250afab1ed
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/crash_debuginfo.ll
@@ -0,0 +1,46 @@
+; RUN: opt -module-summary -o %t-dst.bc %s
+; RUN: opt -module-summary -o %t-src.bc %p/Inputs/crash_debuginfo.ll
+; RUN: llvm-lto -thinlto -o %t-index %t-dst.bc %t-src.bc
+; RUN: opt -function-import -inline -summary-file %t-index.thinlto.bc %t-dst.bc -o %t.out
+; RUN: llvm-nm %t.out | FileCheck %s
+
+; Verify that we import bar and inline it. It use to crash importing due to ODR type uniquing
+; CHECK-NOT: bar
+; CHECK: foo
+; CHECK-NOT: bar
+
+; ModuleID = 'test/ThinLTO/X86/crash_debuginfo.ll'
+source_filename = "test/ThinLTO/X86/crash_debuginfo.ll"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.7.0"
+
+%some_type = type { i32 }
+
+define void @foo(i32 %arg) {
+ call void @bar(i32 %arg), !dbg !7
+ unreachable
+}
+
+declare void @bar(i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "Apple LLVM version 8.0.0 (clang-800.0.24.1)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2)
+!1 = !DIFile(filename: "1.cpp", directory: "/another_dir")
+!2 = !{!3}
+!3 = distinct !DIGlobalVariable(name: "_", linkageName: "some_global", scope: null, file: !1, line: 20, type: !4, isLocal: true, isDefinition: true, variable: %some_type* undef)
+!4 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "slice_nil", file: !1, line: 13, size: 64, align: 64, elements: !5, identifier: "_ZTSN5boost6python3api9slice_nilE")
+!5 = !{}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = distinct !DILocation(line: 728, column: 71, scope: !8, inlinedAt: !15)
+!8 = distinct !DISubprogram(name: "baz", linkageName: "baz", scope: !9, file: !1, line: 726, type: !10, isLocal: false, isDefinition: true, scopeLine: 727, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !11, variables: !12)
+!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "some_other_class", file: !1, line: 197, size: 192, align: 64, elements: !5, templateParams: !5, identifier: "some_other_class")
+!10 = !DISubroutineType(types: !5)
+!11 = !DISubprogram(name: "baz", linkageName: "baz", scope: !9, file: !1, line: 726, type: !10, isLocal: false, isDefinition: false, scopeLine: 726, flags: DIFlagPrototyped, isOptimized: true)
+!12 = !{!13}
+!13 = !DILocalVariable(name: "caster", scope: !8, file: !1, line: 728, type: !14)
+!14 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !8, file: !1, line: 728, size: 64, align: 64, elements: !5, identifier: "someclass")
+!15 = distinct !DILocation(line: 87, column: 9, scope: !16)
+!16 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !9, line: 73, type: !10, isLocal: false, isDefinition: true, scopeLine: 74, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !17, variables: !5)
+!17 = !DISubprogram(name: "foo", linkageName: "foo", scope: !9, file: !1, line: 83, type: !10, isLocal: false, isDefinition: false, scopeLine: 83, flags: DIFlagPrototyped, isOptimized: true)
OpenPOWER on IntegriCloud