1 2; RUN: llc -mtriple=x86_64-linux -O0 -filetype=obj < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s 3; RUN: llc -mtriple=x86_64-linux -O0 -filetype=obj < %s | llvm-dwarfdump -verify - | FileCheck %s --check-prefix VERIFY 4 5; IR generated with `clang++ -g -emit-llvm -S` from the following code: 6; template<typename T> T var; 7; enum e : unsigned char { E = (e)-1 }; 8; template<int x, int*, template<typename> class y, decltype(nullptr) n, e, int ...z> int func() { 9; var<int> = 5; 10; return var<int>; 11; } 12; template<typename> struct y_impl { struct nested { }; }; 13; int glbl = func<3, &glbl, y_impl, nullptr, E, 1, 2>(); 14; y_impl<int>::nested n; 15 16; VERIFY-NOT: error: 17 18; CHECK: [[INT:0x[0-9a-f]*]]:{{ *}}DW_TAG_base_type 19; CHECK-NEXT: DW_AT_name{{.*}} = "int" 20 21; CHECK: DW_TAG_structure_type 22; CHECK: DW_AT_name{{.*}}"y_impl<int>" 23; CHECK-NOT: {{TAG|NULL}} 24; CHECK: DW_TAG_template_type_parameter 25 26; CHECK: DW_TAG_variable 27; CHECK-NEXT: DW_AT_name{{.*}}"var" 28; CHECK-NOT: NULL 29; CHECK: DW_TAG_template_type_parameter 30; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]} 31; CHECK-NEXT: DW_AT_name{{.*}}= "T" 32 33 34; CHECK: DW_AT_name{{.*}}"func<3, &glbl, y_impl, nullptr, E, 1, 2>" 35; CHECK-NOT: NULL 36; CHECK: DW_TAG_template_value_parameter 37; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]} 38; CHECK-NEXT: DW_AT_name{{.*}}= "x" 39; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(3) 40 41; CHECK: DW_TAG_template_value_parameter 42; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INTPTR:0x[0-9a-f]*]]} 43 44; The address of the global 'glbl', followed by DW_OP_stack_value (9f), to use 45; the value immediately, rather than indirecting through the address. 46 47; CHECK-NEXT: DW_AT_location [DW_FORM_exprloc]{{ *}}(DW_OP_addr 0x0, DW_OP_stack_value) 48; CHECK-NOT: NULL 49 50; CHECK: DW_TAG_GNU_template_template_param 51; CHECK-NEXT: DW_AT_name{{.*}}= "y" 52; CHECK-NEXT: DW_AT_GNU_template_name{{.*}}= "y_impl" 53; CHECK-NOT: NULL 54 55; CHECK: DW_TAG_template_value_parameter 56; CHECK-NEXT: DW_AT_type{{.*}}=> {[[NULLPTR:0x[0-9a-f]*]]} 57; CHECK-NEXT: DW_AT_name{{.*}}= "n" 58; CHECK-NEXT: DW_AT_const_value [DW_FORM_udata]{{.*}}(0) 59 60; CHECK: DW_TAG_template_value_parameter 61; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} "e") 62; CHECK: DW_AT_const_value [DW_FORM_udata] (255) 63 64; CHECK: DW_TAG_GNU_template_parameter_pack 65; CHECK-NOT: NULL 66; CHECK: DW_TAG_template_value_parameter 67; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]} 68; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(1) 69; CHECK-NOT: NULL 70; CHECK: DW_TAG_template_value_parameter 71; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]} 72; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(2) 73 74; CHECK: [[INTPTR]]:{{ *}}DW_TAG_pointer_type 75; CHECK-NEXT: DW_AT_type{{.*}} => {[[INT]]} 76 77; CHECK: [[NULLPTR]]:{{ *}}DW_TAG_unspecified_type 78; CHECK-NEXT: DW_AT_name{{.*}}= "decltype(nullptr)" 79 80source_filename = "test.cpp" 81target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 82target triple = "x86_64-unknown-linux-gnu" 83 84%"struct.y_impl<int>::nested" = type { i8 } 85 86$_Z4funcILi3EXadL_Z4glblEE6y_implLDn0EL1e255EJLi1ELi2EEEiv = comdat any 87 88$_Z3varIiE = comdat any 89 90@glbl = dso_local global i32 0, align 4, !dbg !0 91@n = dso_local global %"struct.y_impl<int>::nested" zeroinitializer, align 1, !dbg !10 92@_Z3varIiE = linkonce_odr dso_local global i32 0, comdat, align 4, !dbg !18 93@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_test.cpp, ptr null }] 94 95; Function Attrs: noinline uwtable 96define internal void @__cxx_global_var_init() #0 section ".text.startup" !dbg !28 { 97entry: 98 %call = call i32 @_Z4funcILi3EXadL_Z4glblEE6y_implLDn0EL1e255EJLi1ELi2EEEiv(), !dbg !31 99 store i32 %call, ptr @glbl, align 4, !dbg !32 100 ret void, !dbg !31 101} 102 103; Function Attrs: mustprogress noinline nounwind optnone uwtable 104define linkonce_odr dso_local i32 @_Z4funcILi3EXadL_Z4glblEE6y_implLDn0EL1e255EJLi1ELi2EEEiv() #1 comdat !dbg !33 { 105entry: 106 store i32 5, ptr @_Z3varIiE, align 4, !dbg !48 107 %0 = load i32, ptr @_Z3varIiE, align 4, !dbg !49 108 ret i32 %0, !dbg !50 109} 110 111; Function Attrs: noinline uwtable 112define internal void @_GLOBAL__sub_I_test.cpp() #0 section ".text.startup" !dbg !51 { 113entry: 114 call void @__cxx_global_var_init(), !dbg !53 115 ret void 116} 117 118attributes #0 = { noinline uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 119attributes #1 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 120 121!llvm.dbg.cu = !{!2} 122!llvm.module.flags = !{!22, !23, !24, !25, !26} 123!llvm.ident = !{!27} 124 125!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 126!1 = distinct !DIGlobalVariable(name: "glbl", scope: !2, file: !3, line: 8, type: !17, isLocal: false, isDefinition: true) 127!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0 (git@github.com:llvm/llvm-project.git d0046d018934b284c995408a117371606472cd2a)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !9, splitDebugInlining: false, nameTableKind: None) 128!3 = !DIFile(filename: "test.cpp", directory: "") 129!4 = !{!5} 130!5 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "e", file: !3, line: 2, baseType: !6, size: 8, elements: !7, identifier: "_ZTS1e") 131!6 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) 132!7 = !{!8} 133!8 = !DIEnumerator(name: "E", value: 255, isUnsigned: true) 134!9 = !{!0, !10, !18} 135!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) 136!11 = distinct !DIGlobalVariable(name: "n", scope: !2, file: !3, line: 9, type: !12, isLocal: false, isDefinition: true) 137!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "nested", scope: !13, file: !3, line: 7, size: 8, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTSN6y_implIiE6nestedE") 138!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "y_impl<int>", file: !3, line: 7, size: 8, flags: DIFlagTypePassByValue, elements: !14, templateParams: !15, identifier: "_ZTS6y_implIiE") 139!14 = !{} 140!15 = !{!16} 141!16 = !DITemplateTypeParameter(type: !17) 142!17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 143!18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression()) 144!19 = distinct !DIGlobalVariable(name: "var", linkageName: "_Z3varIiE", scope: !2, file: !3, line: 1, type: !17, isLocal: false, isDefinition: true, templateParams: !20) 145!20 = !{!21} 146!21 = !DITemplateTypeParameter(name: "T", type: !17) 147!22 = !{i32 7, !"Dwarf Version", i32 4} 148!23 = !{i32 2, !"Debug Info Version", i32 3} 149!24 = !{i32 1, !"wchar_size", i32 4} 150!25 = !{i32 7, !"uwtable", i32 1} 151!26 = !{i32 7, !"frame-pointer", i32 2} 152!27 = !{!"clang version 14.0.0 (git@github.com:llvm/llvm-project.git d0046d018934b284c995408a117371606472cd2a)"} 153!28 = distinct !DISubprogram(name: "__cxx_global_var_init", scope: !3, file: !3, type: !29, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, retainedNodes: !14) 154!29 = !DISubroutineType(types: !30) 155!30 = !{null} 156!31 = !DILocation(line: 8, column: 12, scope: !28) 157!32 = !DILocation(line: 0, scope: !28) 158!33 = distinct !DISubprogram(name: "func<3, &glbl, y_impl, nullptr, E, 1, 2>", linkageName: "_Z4funcILi3EXadL_Z4glblEE6y_implLDn0EL1e255EJLi1ELi2EEEiv", scope: !3, file: !3, line: 3, type: !34, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, templateParams: !36, retainedNodes: !14) 159!34 = !DISubroutineType(types: !35) 160!35 = !{!17} 161!36 = !{!37, !38, !40, !41, !43, !44} 162!37 = !DITemplateValueParameter(name: "x", type: !17, value: i32 3) 163!38 = !DITemplateValueParameter(type: !39, value: ptr @glbl) 164!39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64) 165!40 = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "y", value: !"y_impl") 166!41 = !DITemplateValueParameter(name: "n", type: !42, value: i8 0) 167!42 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 168!43 = !DITemplateValueParameter(type: !5, value: i8 -1) 169!44 = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "z", value: !45) 170!45 = !{!46, !47} 171!46 = !DITemplateValueParameter(type: !17, value: i32 1) 172!47 = !DITemplateValueParameter(type: !17, value: i32 2) 173!48 = !DILocation(line: 4, column: 11, scope: !33) 174!49 = !DILocation(line: 5, column: 9, scope: !33) 175!50 = !DILocation(line: 5, column: 2, scope: !33) 176!51 = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_test.cpp", scope: !3, file: !3, type: !52, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, retainedNodes: !14) 177!52 = !DISubroutineType(types: !14) 178!53 = !DILocation(line: 0, scope: !51) 179