Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -954,7 +954,7 @@ NewGV->setLinkage(GlobalValue::InternalLinkage); Constant *C = NewGV; - if (DGV) + if (DGV && NewGV != SGV) C = ConstantExpr::getBitCast(NewGV, TypeMap.get(SGV->getType())); if (DGV && NewGV != DGV) { Index: test/ThinLTO/X86/Inputs/dicompositetype-unique2.ll =================================================================== --- /dev/null +++ test/ThinLTO/X86/Inputs/dicompositetype-unique2.ll @@ -0,0 +1,56 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-scei-ps4" + +%struct.CFVS = type { %struct.Vec } +%struct.Vec = type { i8 } +%struct.S = type { i8 } + +define void @_ZN4CFVSD2Ev(%struct.CFVS* %this) unnamed_addr align 2 !dbg !8 { +entry: + %this.addr = alloca %struct.CFVS*, align 8 + store %struct.CFVS* %this, %struct.CFVS** %this.addr, align 8 + %this1 = load %struct.CFVS*, %struct.CFVS** %this.addr, align 8 + %m_val = getelementptr inbounds %struct.CFVS, %struct.CFVS* %this1, i32 0, i32 0, !dbg !31 + ret void, !dbg !33 +} + +declare dereferenceable(1) %struct.S* @_Z3Getv() + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "bz188598-b.cpp", directory: "") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!"clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)"} +!8 = distinct !DISubprogram(name: "~CFVS", linkageName: "_ZN4CFVSD2Ev", scope: !9, file: !1, line: 2, type: !28, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !27, variables: !2) +!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "CFVS", file: !10, line: 7, size: 8, elements: !11, identifier: "_ZTS4CFVS") +!10 = !DIFile(filename: "./bz188598.h", directory: "") +!11 = !{!12, !27} +!12 = !DIDerivedType(tag: DW_TAG_member, name: "m_val", scope: !9, file: !10, line: 9, baseType: !13, size: 8) +!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Vec<&Get>", file: !10, line: 4, size: 8, elements: !14, templateParams: !19, identifier: "_ZTS3VecIXadL_Z3GetvEEE") +!14 = !{!15} +!15 = !DISubprogram(name: "~Vec", scope: !13, file: !10, line: 5, type: !16, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false) +!16 = !DISubroutineType(types: !17) +!17 = !{null, !18} +!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!19 = !{!20} +!20 = !DITemplateValueParameter(name: "F", type: !21, value: %struct.S* ()* @_Z3Getv) +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64) +!22 = !DIDerivedType(tag: DW_TAG_typedef, name: "Func", file: !10, line: 2, baseType: !23) +!23 = !DISubroutineType(types: !24) +!24 = !{!25} +!25 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !26, size: 64) +!26 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !10, line: 1, flags: DIFlagFwdDecl, identifier: "_ZTS1S") +!27 = !DISubprogram(name: "~CFVS", scope: !9, file: !10, line: 8, type: !28, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false) +!28 = !DISubroutineType(types: !29) +!29 = !{null, !30} +!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!31 = !DILocation(line: 2, scope: !32) +!32 = distinct !DILexicalBlock(scope: !8, file: !1, line: 2) +!33 = !DILocation(line: 2, scope: !8) Index: test/ThinLTO/X86/dicompositetype-unique2.ll =================================================================== --- /dev/null +++ test/ThinLTO/X86/dicompositetype-unique2.ll @@ -0,0 +1,94 @@ +; RUN: opt -module-summary -o %t1.bc %s +; RUN: opt -module-summary -o %t2.bc %S/Inputs/dicompositetype-unique2.ll +; RUN: llvm-lto --thinlto-action=run %t1.bc %t2.bc -thinlto-save-temps=%t3. +; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s +; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t --save-temps \ +; RUN: -r %t1.bc,_ZN1CD2Ev,pl \ +; RUN: -r %t1.bc,_ZN4CFVSD2Ev,l \ +; RUN: -r %t1.bc,_Z3Getv,l \ +; RUN: -r %t2.bc,_ZN4CFVSD2Ev,pl \ +; RUN: -r %t2.bc,_Z3Getv,l +; RUN: llvm-dis %t.1.3.import.bc -o - | FileCheck %s + +; Only llvm-lto2 adds the dso_local keyword, hence the {{.*}} +; CHECK: define available_externally{{.*}} void @_ZN4CFVSD2Ev + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-scei-ps4" + +%class.C = type <{ i32 (...)**, %class.A, %struct.CFVS, [6 x i8] }> +%class.A = type { %struct.Vec } +%struct.Vec = type { i8 } +%struct.CFVS = type { %struct.Vec } +%struct.S = type { i8 } + +define void @_ZN1CD2Ev(%class.C* %this) unnamed_addr align 2 !dbg !8 { +entry: + %this.addr = alloca %class.C*, align 8 + %this1 = load %class.C*, %class.C** %this.addr, align 8 + %m = getelementptr inbounds %class.C, %class.C* %this1, i32 0, i32 2, !dbg !50 + call void @_ZN4CFVSD2Ev(%struct.CFVS* %m), !dbg !50 + ret void, !dbg !52 +} + +declare void @_ZN4CFVSD2Ev(%struct.CFVS*) unnamed_addr + +declare dereferenceable(1) %struct.S* @_Z3Getv() + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "bz188598-a.cpp", directory: ".") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!"clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)"} +!8 = distinct !DISubprogram(name: "~C", linkageName: "_ZN1CD2Ev", scope: !9, file: !1, line: 9, type: !47, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !46, variables: !2) +!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !1, line: 5, size: 128, elements: !10, vtableHolder: !9, identifier: "_ZTS1C") +!10 = !{!11, !32, !38, !46} +!11 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !9, baseType: !12, offset: 64) +!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A >", file: !1, line: 2, size: 8, elements: !13, templateParams: !30, identifier: "_ZTS1AI3VecIXadL_Z3GetvEEEE") +!13 = !{!14} +!14 = !DIDerivedType(tag: DW_TAG_member, name: "m_t", scope: !12, file: !1, line: 3, baseType: !15, size: 8) +!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Vec<&Get>", file: !16, line: 4, size: 8, elements: !17, templateParams: !22, identifier: "_ZTS3VecIXadL_Z3GetvEEE") +!16 = !DIFile(filename: "./bz188598.h", directory: ".") +!17 = !{!18} +!18 = !DISubprogram(name: "~Vec", scope: !15, file: !16, line: 5, type: !19, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false) +!19 = !DISubroutineType(types: !20) +!20 = !{null, !21} +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!22 = !{!23} +!23 = !DITemplateValueParameter(name: "F", type: !24, value: %struct.S* ()* @_Z3Getv) +!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !25, size: 64) +!25 = !DIDerivedType(tag: DW_TAG_typedef, name: "Func", file: !16, line: 2, baseType: !26) +!26 = !DISubroutineType(types: !27) +!27 = !{!28} +!28 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !29, size: 64) +!29 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !16, line: 1, flags: DIFlagFwdDecl, identifier: "_ZTS1S") +!30 = !{!31} +!31 = !DITemplateTypeParameter(name: "T", type: !15) +!32 = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$C", scope: !1, file: !1, baseType: !33, size: 64, flags: DIFlagArtificial) +!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64) +!34 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__vtbl_ptr_type", baseType: !35, size: 64) +!35 = !DISubroutineType(types: !36) +!36 = !{!37} +!37 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!38 = !DIDerivedType(tag: DW_TAG_member, name: "m", scope: !9, file: !1, line: 7, baseType: !39, size: 8, offset: 72) +!39 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "CFVS", file: !16, line: 7, size: 8, elements: !40, identifier: "_ZTS4CFVS") +!40 = !{!41, !42} +!41 = !DIDerivedType(tag: DW_TAG_member, name: "m_val", scope: !39, file: !16, line: 9, baseType: !15, size: 8) +!42 = !DISubprogram(name: "~CFVS", scope: !39, file: !16, line: 8, type: !43, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false) +!43 = !DISubroutineType(types: !44) +!44 = !{null, !45} +!45 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !39, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!46 = !DISubprogram(name: "~C", scope: !9, file: !1, line: 6, type: !47, isLocal: false, isDefinition: false, scopeLine: 6, containingType: !9, virtuality: DW_VIRTUALITY_virtual, virtualIndex: 0, flags: DIFlagPrototyped, isOptimized: false) +!47 = !DISubroutineType(types: !48) +!48 = !{null, !49} +!49 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!50 = !DILocation(line: 9, scope: !51) +!51 = distinct !DILexicalBlock(scope: !8, file: !1, line: 9) +!52 = !DILocation(line: 9, scope: !8)