Index: llvm/lib/IR/LLVMContextImpl.h =================================================================== --- llvm/lib/IR/LLVMContextImpl.h +++ llvm/lib/IR/LLVMContextImpl.h @@ -612,17 +612,19 @@ typedef MDNodeKeyImpl KeyTy; static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope, - LHS.LinkageName, RHS); + LHS.LinkageName, LHS.TemplateParams, RHS); } static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), - LHS->getRawLinkageName(), RHS); + LHS->getRawLinkageName(), + LHS->getRawTemplateParams(), RHS); } /// Subprograms compare equal if they declare the same function in an ODR /// type. static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope, const MDString *LinkageName, + const Metadata *TemplateParams, const DISubprogram *RHS) { // Check whether the LHS is eligible. if (IsDefinition || !Scope || !LinkageName) @@ -634,7 +636,8 @@ // Compare to the RHS. return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() && - LinkageName == RHS->getRawLinkageName(); + LinkageName == RHS->getRawLinkageName() && + TemplateParams == RHS->getRawTemplateParams(); } }; Index: llvm/test/Transforms/Util/clone-dicompileunit.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/Util/clone-dicompileunit.ll @@ -0,0 +1,79 @@ +; RUN: opt -run-twice -verify -disable-debug-info-type-map -S -o - %s | FileCheck %s + +; Generated using: +; $ cat p.cpp +; class C; +; class A { +; public: +; A(C *); +; }; +; class B { +; public: +; template void m_fn2() { static int a; } +; virtual void m_fn1(); +; }; +; +; class C : public B {}; +; void fn1() { +; class D : public C { +; public: +; D() { m_fn2(); } +; }; +; A(new D); +; } +; $ clang++ -target x86_64-unknown-linux -fvisibility=hidden -O2 -g2 -flto -S p.cpp -o p.ll +; # then manually removed function/gv definitions + +; CHECK: DICompileUnit +; CHECK-NOT: DICompileUnit + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!39, !40, !41} +!llvm.ident = !{!42} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !15) +!1 = !DIFile(filename: "p.cpp", directory: "") +!2 = !{} +!3 = !{!4} +!4 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !1, line: 2, size: 8, elements: !5, identifier: "_ZTS1A") +!5 = !{!6} +!6 = !DISubprogram(name: "A", scope: !4, file: !1, line: 4, type: !7, isLocal: false, isDefinition: false, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!7 = !DISubroutineType(types: !8) +!8 = !{null, !9, !10} +!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) +!11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !1, line: 12, size: 64, elements: !12, vtableHolder: !14, identifier: "_ZTS1C") +!12 = !{!13} +!13 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !11, baseType: !14, flags: DIFlagPublic) +!14 = !DICompositeType(tag: DW_TAG_class_type, name: "B", file: !1, line: 6, flags: DIFlagFwdDecl, identifier: "_ZTS1B") +!15 = !{!16} +!16 = !DIGlobalVariableExpression(var: !17) +!17 = distinct !DIGlobalVariable(name: "a", scope: !18, file: !1, line: 8, type: !38, isLocal: true, isDefinition: true) +!18 = distinct !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2IZ3fn1vE1DEEvv", scope: !14, file: !1, line: 8, type: !19, isLocal: true, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !22, declaration: !34, variables: !35) +!19 = !DISubroutineType(types: !20) +!20 = !{null, !21} +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!22 = !{!23} +!23 = !DITemplateTypeParameter(type: !24) +!24 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "D", scope: !25, file: !1, line: 14, size: 64, elements: !28, vtableHolder: !14) +!25 = distinct !DISubprogram(name: "fn1", linkageName: "_Z3fn1v", scope: !1, file: !1, line: 13, type: !26, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) +!26 = !DISubroutineType(types: !27) +!27 = !{null} +!28 = !{!29, !30} +!29 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !24, baseType: !11, flags: DIFlagPublic) +!30 = !DISubprogram(name: "D", scope: !24, file: !1, line: 16, type: !31, isLocal: false, isDefinition: false, scopeLine: 16, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!31 = !DISubroutineType(types: !32) +!32 = !{null, !33} +!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !24, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!34 = !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2IZ3fn1vE1DEEvv", scope: !14, file: !1, line: 8, type: !19, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true, templateParams: !22) +!35 = !{!36} +!36 = !DILocalVariable(name: "this", arg: 1, scope: !18, type: !37, flags: DIFlagArtificial | DIFlagObjectPointer) +!37 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) +!38 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!39 = !{i32 2, !"Dwarf Version", i32 4} +!40 = !{i32 2, !"Debug Info Version", i32 3} +!41 = !{i32 1, !"PIC Level", i32 2} +!42 = !{!"clang version 5.0.0 "}