Index: llvm/lib/LTO/LTO.cpp =================================================================== --- llvm/lib/LTO/LTO.cpp +++ llvm/lib/LTO/LTO.cpp @@ -871,8 +871,8 @@ GlobalValue *GV = RegularLTO.CombinedModule->getNamedValue(R.second.IRName); - // Ignore symbols defined in other partitions. - if (!GV || GV->hasLocalLinkage()) + // Ignore declarations and symbols defined in other partitions. + if (!GV || GV->hasLocalLinkage() || GV->isDeclaration()) continue; GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global : GlobalValue::UnnamedAddr::None); Index: llvm/test/LTO/X86/Inputs/pr38046.m.ll =================================================================== --- /dev/null +++ llvm/test/LTO/X86/Inputs/pr38046.m.ll @@ -0,0 +1,118 @@ +; ModuleID = 'm.o' +source_filename = "m.cc" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%class.A = type { i8 } + +$_ZN1AC2Ev = comdat any + +@.str = private unnamed_addr constant [4 x i8] c"bar\00", align 1 + +; Function Attrs: norecurse uwtable +define hidden i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #0 !dbg !7 { +entry: + %t = alloca %class.A, align 1 + call void @llvm.dbg.value(metadata i32 %argc, metadata !15, metadata !DIExpression()), !dbg !38 + call void @llvm.dbg.value(metadata i8** %argv, metadata !16, metadata !DIExpression()), !dbg !39 + %0 = getelementptr inbounds %class.A, %class.A* %t, i64 0, i32 0, !dbg !40 + call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %0) #5, !dbg !40 + call void @llvm.dbg.value(metadata %class.A* %t, metadata !17, metadata !DIExpression()), !dbg !41 + call void @_ZN1AC2Ev(%class.A* nonnull %t) #5, !dbg !41 + call void @llvm.dbg.value(metadata %class.A* %t, metadata !17, metadata !DIExpression()), !dbg !41 + %call = call i32 @_ZN1A3fooEPKc(%class.A* nonnull %t, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)), !dbg !42 + call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %0) #5, !dbg !43 + ret i32 0, !dbg !44 +} + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 + +; Function Attrs: inlinehint nounwind uwtable +define linkonce_odr hidden void @_ZN1AC2Ev(%class.A* %this) unnamed_addr #2 comdat align 2 !dbg !45 { +entry: + call void @llvm.dbg.value(metadata %class.A* %this, metadata !50, metadata !DIExpression()), !dbg !52 + %_a = getelementptr inbounds %class.A, %class.A* %this, i64 0, i32 0, !dbg !53 + store i8 0, i8* %_a, align 1, !dbg !53, !tbaa !54 + ret void, !dbg !59 +} + +declare dso_local i32 @_ZN1A3fooEPKc(%class.A*, i8*) local_unnamed_addr #3 + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #4 + +attributes #0 = { norecurse uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { argmemonly nounwind } +attributes #2 = { inlinehint nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #4 = { nounwind readnone speculatable } +attributes #5 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "m.cc", directory: "/tmp/t") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 7.0.0 "} +!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !14) +!8 = !DISubroutineType(types: !9) +!9 = !{!10, !10, !11} +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) +!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !{!15, !16, !17} +!15 = !DILocalVariable(name: "argc", arg: 1, scope: !7, file: !1, line: 3, type: !10) +!16 = !DILocalVariable(name: "argv", arg: 2, scope: !7, file: !1, line: 3, type: !11) +!17 = !DILocalVariable(name: "t", scope: !7, file: !1, line: 4, type: !18) +!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !19, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !20, identifier: "_ZTS1A") +!19 = !DIFile(filename: "./t.h", directory: "/tmp/t") +!20 = !{!21, !23, !28, !34} +!21 = !DIDerivedType(tag: DW_TAG_member, name: "_a", scope: !18, file: !19, line: 6, baseType: !22, size: 8, flags: DIFlagPublic) +!22 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) +!23 = !DISubprogram(name: "get", linkageName: "_ZN1A3getEv", scope: !18, file: !19, line: 3, type: !24, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, isOptimized: true) +!24 = !DISubroutineType(types: !25) +!25 = !{!26} +!26 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !27, size: 64) +!27 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !18) +!28 = !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEPKc", scope: !18, file: !19, line: 4, type: !29, isLocal: false, isDefinition: false, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!29 = !DISubroutineType(types: !30) +!30 = !{!10, !31, !32} +!31 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64) +!33 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) +!34 = !DISubprogram(name: "a", linkageName: "_ZNK1A1aEv", scope: !18, file: !19, line: 5, type: !35, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!35 = !DISubroutineType(types: !36) +!36 = !{!22, !37} +!37 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !27, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!38 = !DILocation(line: 3, column: 14, scope: !7) +!39 = !DILocation(line: 3, column: 27, scope: !7) +!40 = !DILocation(line: 4, column: 3, scope: !7) +!41 = !DILocation(line: 4, column: 5, scope: !7) +!42 = !DILocation(line: 5, column: 5, scope: !7) +!43 = !DILocation(line: 7, column: 1, scope: !7) +!44 = !DILocation(line: 6, column: 3, scope: !7) +!45 = distinct !DISubprogram(name: "A", linkageName: "_ZN1AC2Ev", scope: !18, file: !19, line: 1, type: !46, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !48, retainedNodes: !49) +!46 = !DISubroutineType(types: !47) +!47 = !{null, !31} +!48 = !DISubprogram(name: "A", scope: !18, type: !46, isLocal: false, isDefinition: false, flags: DIFlagPublic | DIFlagArtificial | DIFlagPrototyped, isOptimized: true) +!49 = !{!50} +!50 = !DILocalVariable(name: "this", arg: 1, scope: !45, type: !51, flags: DIFlagArtificial | DIFlagObjectPointer) +!51 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64) +!52 = !DILocation(line: 0, scope: !45) +!53 = !DILocation(line: 6, column: 8, scope: !45) +!54 = !{!55, !56, i64 0} +!55 = !{!"_ZTS1A", !56, i64 0} +!56 = !{!"bool", !57, i64 0} +!57 = !{!"omnipotent char", !58, i64 0} +!58 = !{!"Simple C++ TBAA"} +!59 = !DILocation(line: 1, column: 7, scope: !45) Index: llvm/test/LTO/X86/pr38046.ll =================================================================== --- /dev/null +++ llvm/test/LTO/X86/pr38046.ll @@ -0,0 +1,132 @@ +; RUN: rm -fr %t +; RUN: mkdir -p %t +; RUN: opt -module-summary -o %t/t.o %s +; RUN: opt -o %t/m.o %S/Inputs/pr38046.m.ll +; RUN: cd %t +; RUN: llvm-lto2 run -save-temps -o m m.o t.o \ +; RUN: -r=m.o,main,plx \ +; RUN: -r=m.o,_ZN1AC2Ev,pl \ +; RUN: -r=m.o,_ZN1A3fooEPKc,l \ +; RUN: -r=t.o,_ZN1A3fooEPKc,pl \ +; RUN: -r=t.o,_ZN1A3getEv,pl +; RUN: llvm-dis m.0.2.internalize.bc > /dev/null + +; ModuleID = 't.o' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%class.A = type { i8 } + +@_ZL8instance = internal global %class.A zeroinitializer, align 1, !dbg !0 + +; Function Attrs: nounwind readonly uwtable +define hidden i32 @_ZN1A3fooEPKc(%class.A* nocapture readnone %this, i8* readnone %from) local_unnamed_addr #0 align 2 !dbg !35 !type !41 { +entry: + call void @llvm.dbg.value(metadata %class.A* %this, metadata !37, metadata !DIExpression()), !dbg !42 + call void @llvm.dbg.value(metadata i8* %from, metadata !39, metadata !DIExpression()), !dbg !43 + call void @llvm.dbg.value(metadata i8* %from, metadata !44, metadata !DIExpression()), !dbg !53 + call void @llvm.dbg.value(metadata %class.A* ()* @_ZN1A3getEv, metadata !49, metadata !DIExpression()), !dbg !55 + call void @llvm.dbg.value(metadata %class.A* @_ZL8instance, metadata !56, metadata !DIExpression()), !dbg !59 + %0 = load i8, i8* getelementptr inbounds (%class.A, %class.A* @_ZL8instance, i64 0, i32 0), align 1, !dbg !61, !tbaa !62, !range !67 + %tobool.i.i = icmp eq i8 %0, 0, !dbg !61 + %. = select i1 %tobool.i.i, i32 42, i32 123, !dbg !68 + ret i32 %., !dbg !71 +} + +; Function Attrs: norecurse nounwind readnone uwtable +define hidden nonnull dereferenceable(1) %class.A* @_ZN1A3getEv() local_unnamed_addr #1 align 2 !dbg !72 { +entry: + ret %class.A* @_ZL8instance, !dbg !73 +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #2 + +attributes #0 = { nounwind readonly uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!30, !31, !32, !33} +!llvm.ident = !{!34} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "instance", linkageName: "_ZL8instance", scope: !2, file: !3, line: 3, type: !8, isLocal: true, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !29) +!3 = !DIFile(filename: "t.cc", directory: "/tmp/t") +!4 = !{} +!5 = !{!6} +!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) +!7 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8) +!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !9, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !10, identifier: "_ZTS1A") +!9 = !DIFile(filename: "./t.h", directory: "/tmp/t") +!10 = !{!11, !13, !17, !25} +!11 = !DIDerivedType(tag: DW_TAG_member, name: "_a", scope: !8, file: !9, line: 6, baseType: !12, size: 8, flags: DIFlagPublic) +!12 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) +!13 = !DISubprogram(name: "get", linkageName: "_ZN1A3getEv", scope: !8, file: !9, line: 3, type: !14, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, isOptimized: true) +!14 = !DISubroutineType(types: !15) +!15 = !{!16} +!16 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !7, size: 64) +!17 = !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEPKc", scope: !8, file: !9, line: 4, type: !18, isLocal: false, isDefinition: false, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!18 = !DISubroutineType(types: !19) +!19 = !{!20, !21, !22} +!20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64) +!23 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !24) +!24 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!25 = !DISubprogram(name: "a", linkageName: "_ZNK1A1aEv", scope: !8, file: !9, line: 5, type: !26, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) +!26 = !DISubroutineType(types: !27) +!27 = !{!12, !28} +!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!29 = !{!0} +!30 = !{i32 2, !"Dwarf Version", i32 4} +!31 = !{i32 2, !"Debug Info Version", i32 3} +!32 = !{i32 1, !"wchar_size", i32 4} +!33 = !{i32 1, !"ThinLTO", i32 0} +!34 = !{!"clang version 7.0.0 "} +!35 = distinct !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEPKc", scope: !8, file: !3, line: 5, type: !18, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !17, retainedNodes: !36) +!36 = !{!37, !39, !40} +!37 = !DILocalVariable(name: "this", arg: 1, scope: !35, type: !38, flags: DIFlagArtificial | DIFlagObjectPointer) +!38 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64) +!39 = !DILocalVariable(name: "from", arg: 2, scope: !35, file: !3, line: 5, type: !22) +!40 = !DILocalVariable(name: "source", scope: !35, file: !3, line: 6, type: !6) +!41 = !{i64 0, !"_ZTSM1AFiPKcE"} +!42 = !DILocation(line: 0, scope: !35) +!43 = !DILocation(line: 5, column: 24, scope: !35) +!44 = !DILocalVariable(name: "from", arg: 1, scope: !45, file: !9, line: 10, type: !22) +!45 = distinct !DISubprogram(name: "cast", linkageName: "_Z4castI1AEPKT_PKc", scope: !9, file: !9, line: 10, type: !46, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: true, unit: !2, templateParams: !51, retainedNodes: !48) +!46 = !DISubroutineType(types: !47) +!47 = !{!6, !22} +!48 = !{!44, !49} +!49 = !DILocalVariable(name: "get", scope: !45, file: !9, line: 11, type: !50) +!50 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) +!51 = !{!52} +!52 = !DITemplateTypeParameter(name: "T", type: !8) +!53 = !DILocation(line: 10, column: 27, scope: !45, inlinedAt: !54) +!54 = distinct !DILocation(line: 6, column: 21, scope: !35) +!55 = !DILocation(line: 11, column: 14, scope: !45, inlinedAt: !54) +!56 = !DILocalVariable(name: "this", arg: 1, scope: !57, type: !6, flags: DIFlagArtificial | DIFlagObjectPointer) +!57 = distinct !DISubprogram(name: "a", linkageName: "_ZNK1A1aEv", scope: !8, file: !9, line: 5, type: !26, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !25, retainedNodes: !58) +!58 = !{!56} +!59 = !DILocation(line: 0, scope: !57, inlinedAt: !60) +!60 = distinct !DILocation(line: 12, column: 16, scope: !45, inlinedAt: !54) +!61 = !DILocation(line: 5, column: 27, scope: !57, inlinedAt: !60) +!62 = !{!63, !64, i64 0} +!63 = !{!"_ZTS1A", !64, i64 0} +!64 = !{!"bool", !65, i64 0} +!65 = !{!"omnipotent char", !66, i64 0} +!66 = !{!"Simple C++ TBAA"} +!67 = !{i8 0, i8 2} +!68 = !DILocation(line: 8, column: 5, scope: !69) +!69 = distinct !DILexicalBlock(scope: !70, file: !3, line: 7, column: 26) +!70 = distinct !DILexicalBlock(scope: !35, file: !3, line: 7, column: 7) +!71 = !DILocation(line: 12, column: 1, scope: !35) +!72 = distinct !DISubprogram(name: "get", linkageName: "_ZN1A3getEv", scope: !8, file: !3, line: 14, type: !14, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !13, retainedNodes: !4) +!73 = !DILocation(line: 15, column: 3, scope: !72) + +^0 = module: (path: "t.o", hash: (0, 0, 0, 0, 0)) +^1 = gv: (name: "_ZN1A3getEv", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1), insts: 1, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0), refs: (^2)))) ; guid = 5611323311377169431 +^2 = gv: (name: "_ZL8instance", summaries: (variable: (module: ^0, flags: (linkage: internal, notEligibleToImport: 1, live: 0, dsoLocal: 1)))) ; guid = 6195188191155412884 +^3 = gv: (name: "llvm.dbg.value") ; guid = 7457163675545648777 +^4 = gv: (name: "_ZN1A3fooEPKc", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1), insts: 4, funcFlags: (readNone: 0, readOnly: 1, noRecurse: 0, returnDoesNotAlias: 0), refs: (^2)))) ; guid = 17153645512572898188