1; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t 2; RUN: llvm-dwarfdump -verify %t 3; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s 4; RUN: rm %t 5; 6;$ cat -n 1.cpp 7; 1 struct HHH; 8; 2 HHH *zzz; 9; 10;$ cat -n 2.cpp 11; 1 void __attribute__((optnone)) __attribute__((nodebug)) f1() { } 12; 2 13; 3 struct HHH { 14; 4 template <typename bbb> 15; 5 static int __attribute__((always_inline)) ccc() { 16; 6 f1(); 17; 7 } 18; 8 }; 19; 9 20; 10 int main() { 21; 11 struct local { }; 22; 12 HHH::ccc<local>(); 23; 13 } 24; 25; $ clang -flto -O2 -g 1.cpp 2.cpp -o a.out 26; 27; Given this input, LLVM attempts to create a DIE for subprogram "main" in the 28; wrong context. The definition of struct "HHH" is placed in the CU for 1.cpp. 29; While creating the template instance in "HHH", function "ccc" is referenced 30; via the struct local type, and "main" is created in the CU for 1.cpp, which 31; is incorrect. 32; 33; See PR48790 for more discussion and original compile commands. 34; 35; Check that there are no verifier failures, and that the SP for "main" appears 36; in the correct CU. 37; CHECK-LABEL: DW_TAG_compile_unit 38; CHECK: DW_AT_name ("1.cpp") 39; CHECK-NOT: DW_AT_name ("main") 40; CHECK-LABEL: DW_TAG_compile_unit 41; CHECK: DW_AT_name ("2.cpp") 42; CHECK: DW_TAG_subprogram 43; CHECK: DW_AT_name ("main") 44 45source_filename = "ld-temp.o" 46target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 47target triple = "x86_64-unknown-linux-gnu" 48 49; Function Attrs: noinline norecurse nounwind optnone uwtable mustprogress 50define internal fastcc void @_Z2f1v() unnamed_addr { 51entry: 52 ret void 53} 54 55; Function Attrs: norecurse noreturn nounwind uwtable mustprogress 56define dso_local i32 @main() local_unnamed_addr !dbg !17 { 57entry: 58 tail call fastcc void @_Z2f1v(), !dbg !21 59 unreachable, !dbg !21 60} 61 62!llvm.dbg.cu = !{!0, !9} 63!llvm.ident = !{!10, !10} 64!llvm.module.flags = !{!11, !12, !13, !14, !15} 65 66!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0 (git@github.com:llvm/llvm-project bc9ab9a5cd6bafc5e1293f3d5d51638f8f5cd26c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, splitDebugInlining: false, nameTableKind: None) 67!1 = !DIFile(filename: "1.cpp", directory: "/tmp/bees") 68!2 = !{} 69!3 = !{!4} 70!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) 71!5 = distinct !DIGlobalVariable(name: "zzz", scope: !0, file: !1, line: 2, type: !6, isLocal: false, isDefinition: true) 72!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) 73!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HHH", file: !8, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS3HHH") 74!8 = !DIFile(filename: "2.cpp", directory: "/tmp/bees") 75!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !8, producer: "clang version 12.0.0 (git@github.com:llvm/llvm-project bc9ab9a5cd6bafc5e1293f3d5d51638f8f5cd26c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 76!10 = !{!"clang version 12.0.0 (git@github.com:llvm/llvm-project bc9ab9a5cd6bafc5e1293f3d5d51638f8f5cd26c)"} 77!11 = !{i32 7, !"Dwarf Version", i32 4} 78!12 = !{i32 2, !"Debug Info Version", i32 3} 79!13 = !{i32 1, !"wchar_size", i32 4} 80!14 = !{i32 1, !"ThinLTO", i32 0} 81!15 = !{i32 1, !"EnableSplitLTOUnit", i32 1} 82!17 = distinct !DISubprogram(name: "main", scope: !8, file: !8, line: 10, type: !18, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !9, retainedNodes: !2) 83!18 = !DISubroutineType(types: !19) 84!19 = !{!20} 85!20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 86!21 = !DILocation(line: 6, column: 5, scope: !22, inlinedAt: !27) 87!22 = distinct !DISubprogram(name: "ccc<local>", linkageName: "_ZN3HHH3cccIZ4mainE5localEEiv", scope: !7, file: !8, line: 5, type: !18, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !9, templateParams: !24, declaration: !23, retainedNodes: !2) 88!23 = !DISubprogram(name: "ccc<local>", linkageName: "_ZN3HHH3cccIZ4mainE5localEEiv", scope: !7, file: !8, line: 5, type: !18, scopeLine: 5, flags: DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagOptimized, templateParams: !24) 89!24 = !{!25} 90!25 = !DITemplateTypeParameter(name: "bbb", type: !26) 91!26 = !DICompositeType(tag: DW_TAG_structure_type, name: "local", scope: !17, file: !8, line: 11, size: 8, flags: DIFlagFwdDecl) 92!27 = distinct !DILocation(line: 12, column: 3, scope: !17) 93