1; RUN: llc -mtriple=x86_64-pc-linux-gnu < %s | FileCheck -check-prefix=ASM %s 2; RUN: llc -mtriple=x86_64-pc-linux-gnu -filetype=obj < %s | llvm-dwarfdump -v - | FileCheck %s 3; ModuleID = 'dwarf-public-names.cpp' 4; 5; Generated from: 6; 7; struct C { 8; void member_function(); 9; static int static_member_function(); 10; static int static_member_variable; 11; }; 12; 13; int C::static_member_variable = 0; 14; 15; void C::member_function() { 16; static_member_variable = 0; 17; } 18; 19; int C::static_member_function() { 20; return static_member_variable; 21; } 22; 23; C global_variable; 24; 25; int global_function() { 26; return -1; 27; } 28; 29; namespace ns { 30; void global_namespace_function() { 31; global_variable.member_function(); 32; } 33; int global_namespace_variable = 1; 34; extern int global_namespace_variable_decl; 35; struct D { 36; int A; 37; } d; 38; } 39; 40; using ns::global_namespace_variable_decl; 41; 42; namespace { 43; int i; 44; } 45; 46; int *f3() { 47; static int z; 48; return &z; 49; } 50; 51; namespace { 52; namespace inner { 53; int b; 54; } 55; } 56; 57; namespace outer { 58; namespace { 59; int c; 60; } 61; } 62; 63; int f7() { 64; return i + *f3() + inner::b + outer::c; 65; } 66 67; ASM: .section .debug_gnu_pubnames 68; ASM: .byte 32 # Kind: VARIABLE, EXTERNAL 69; ASM-NEXT: .asciz "global_variable" # External Name 70 71; ASM: .section .debug_gnu_pubtypes 72; ASM: .byte 16 # Kind: TYPE, EXTERNAL 73; ASM-NEXT: .asciz "C" # External Name 74 75; CHECK: .debug_info contents: 76; CHECK: Compile Unit: 77; CHECK: DW_AT_GNU_pubnames [DW_FORM_flag_present] (true) 78; CHECK-NOT: DW_AT_GNU_pubtypes [ 79 80; CHECK: [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable 81; CHECK-NEXT: DW_AT_specification {{.*}} "static_member_variable" 82 83; CHECK: [[C:0x[0-9a-f]+]]: DW_TAG_structure_type 84; CHECK-NEXT: DW_AT_name {{.*}} "C" 85 86; CHECK: DW_TAG_member 87; CHECK-NEXT: DW_AT_name {{.*}} "static_member_variable" 88 89; CHECK: DW_TAG_subprogram 90; CHECK-NEXT: DW_AT_linkage_name 91; CHECK-NEXT: DW_AT_name {{.*}} "member_function" 92 93; CHECK: DW_TAG_subprogram 94; CHECK-NEXT: DW_AT_linkage_name 95; CHECK-NEXT: DW_AT_name {{.*}} "static_member_function" 96 97; CHECK: [[INT:0x[0-9a-f]+]]: DW_TAG_base_type 98; CHECK-NEXT: DW_AT_name {{.*}} "int" 99 100; CHECK: [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable 101; CHECK-NEXT: DW_AT_name {{.*}} "global_variable" 102 103; CHECK: [[NS:0x[0-9a-f]+]]: DW_TAG_namespace 104; CHECK-NEXT: DW_AT_name {{.*}} "ns" 105 106; CHECK: [[GLOB_NS_VAR:0x[0-9a-f]+]]: DW_TAG_variable 107; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_variable" 108; CHECK-NOT: DW_AT_specification 109; CHECK: DW_AT_location 110; CHECK-NOT: DW_AT_specification 111 112; CHECK: [[D_VAR:0x[0-9a-f]+]]: DW_TAG_variable 113; CHECK-NEXT: DW_AT_name {{.*}} "d" 114; CHECK-NOT: DW_AT_specification 115; CHECK: DW_AT_location 116; CHECK-NOT: DW_AT_specification 117 118; CHECK: [[D:0x[0-9a-f]+]]: DW_TAG_structure_type 119; CHECK-NEXT: DW_AT_name {{.*}} "D" 120 121; CHECK: [[GLOB_NS_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram 122; CHECK-NOT: DW_TAG 123; CHECK: DW_AT_linkage_name 124; CHECK-NOT: DW_TAG 125; CHECK: DW_AT_name {{.*}} "global_namespace_function" 126 127; CHECK: DW_TAG_subprogram 128; CHECK-NOT: DW_TAG 129; CHECK: DW_AT_name {{.*}} "f3" 130; CHECK-NOT: {{DW_TAG|NULL}} 131; CHECK: [[F3_Z:.*]]: DW_TAG_variable 132; CHECK-NOT: DW_TAG 133; CHECK: DW_AT_name {{.*}} "z" 134; CHECK-NOT: {{DW_TAG|NULL}} 135; CHECK: DW_AT_location 136; CHECK-NOT: {{DW_TAG|NULL}} 137; CHECK: NULL 138; CHECK-NOT: {{DW_TAG|NULL}} 139 140; CHECK: [[ANON:.*]]: DW_TAG_namespace 141; CHECK-NOT: DW_AT_name 142; CHECK: [[ANON_I:.*]]: DW_TAG_variable 143; CHECK-NOT: DW_TAG 144; CHECK: DW_AT_name {{.*}} "i" 145; CHECK-NOT: {{DW_TAG|NULL}} 146; CHECK: [[ANON_INNER:.*]]: DW_TAG_namespace 147; CHECK-NOT: DW_TAG 148; CHECK: DW_AT_name {{.*}} "inner" 149; CHECK-NOT: {{DW_TAG|NULL}} 150; CHECK: [[ANON_INNER_B:.*]]: DW_TAG_variable 151; CHECK-NOT: DW_TAG 152; CHECK: DW_AT_name {{.*}} "b" 153; CHECK-NOT: {{DW_TAG|NULL}} 154; CHECK: NULL 155; CHECK-NOT: {{DW_TAG|NULL}} 156; CHECK: NULL 157; CHECK-NOT: {{DW_TAG|NULL}} 158 159; CHECK: [[OUTER:.*]]: DW_TAG_namespace 160; CHECK-NOT: DW_TAG 161; CHECK: DW_AT_name {{.*}} "outer" 162; CHECK-NOT: {{DW_TAG|NULL}} 163; CHECK: [[OUTER_ANON:.*]]: DW_TAG_namespace 164; CHECK-NOT: {{DW_TAG|NULL}} 165; CHECK-NOT: DW_AT_name 166; CHECK: [[OUTER_ANON_C:.*]]: DW_TAG_variable 167; CHECK-NOT: DW_TAG 168; CHECK: DW_AT_name {{.*}} "c" 169; CHECK-NOT: {{DW_TAG|NULL}} 170; CHECK: NULL 171; CHECK-NOT: {{DW_TAG|NULL}} 172; FIXME: We probably shouldn't bother describing the implicit 173; import of the preceding anonymous namespace. This should be fixed 174; in clang. 175; CHECK: DW_TAG_imported_module 176; CHECK-NOT: {{DW_TAG|NULL}} 177; CHECK: NULL 178; CHECK-NOT: {{DW_TAG|NULL}} 179 180; CHECK: DW_TAG_imported_declaration 181; CHECK-NOT: {{DW_TAG|NULL}} 182 183; CHECK: [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram 184; CHECK-NOT: DW_TAG 185; CHECK: DW_AT_specification {{.*}} "_ZN1C15member_functionEv" 186 187; CHECK: [[STATIC_MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram 188; CHECK-NOT: DW_TAG 189; CHECK: DW_AT_specification {{.*}} "_ZN1C22static_member_functionEv" 190 191; CHECK: [[GLOBAL_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram 192; CHECK-NOT: DW_TAG 193; CHECK: DW_AT_linkage_name 194; CHECK-NOT: DW_TAG 195; CHECK: DW_AT_name {{.*}} "global_function" 196 197; CHECK-LABEL: .debug_gnu_pubnames contents: 198; CHECK-NEXT: length = {{.*}} version = 0x0002 unit_offset = 0x00000000 unit_size = {{.*}} 199; CHECK-NEXT: Offset Linkage Kind Name 200; CHECK-NEXT: [[GLOBAL_FUNC]] EXTERNAL FUNCTION "global_function" 201; CHECK-NEXT: [[NS]] EXTERNAL TYPE "ns" 202; CHECK-NEXT: [[OUTER_ANON_C]] STATIC VARIABLE "outer::(anonymous namespace)::c" 203; CHECK-NEXT: [[ANON_I]] STATIC VARIABLE "(anonymous namespace)::i" 204; GCC Doesn't put local statics in pubnames, but it seems not unreasonable and 205; comes out naturally from LLVM's implementation, so I'm OK with it for now. If 206; it's demonstrated that this is a major size concern or degrades debug info 207; consumer behavior, feel free to change it. 208; CHECK-NEXT: [[F3_Z]] STATIC VARIABLE "f3::z" 209; CHECK-NEXT: [[ANON]] EXTERNAL TYPE "(anonymous namespace)" 210; CHECK-NEXT: [[OUTER_ANON]] EXTERNAL TYPE "outer::(anonymous namespace)" 211; CHECK-NEXT: [[ANON_INNER_B]] STATIC VARIABLE "(anonymous namespace)::inner::b" 212; CHECK-NEXT: [[OUTER]] EXTERNAL TYPE "outer" 213; CHECK-NEXT: [[MEM_FUNC]] EXTERNAL FUNCTION "C::member_function" 214; CHECK-NEXT: [[GLOB_VAR]] EXTERNAL VARIABLE "global_variable" 215; CHECK-NEXT: [[GLOB_NS_VAR]] EXTERNAL VARIABLE "ns::global_namespace_variable" 216; CHECK-NEXT: [[ANON_INNER]] EXTERNAL TYPE "(anonymous namespace)::inner" 217; CHECK-NEXT: [[D_VAR]] EXTERNAL VARIABLE "ns::d" 218; CHECK-NEXT: [[GLOB_NS_FUNC]] EXTERNAL FUNCTION "ns::global_namespace_function" 219; CHECK-NEXT: [[STATIC_MEM_VAR]] EXTERNAL VARIABLE "C::static_member_variable" 220; CHECK-NEXT: [[STATIC_MEM_FUNC]] EXTERNAL FUNCTION "C::static_member_function" 221 222; CHECK-LABEL: debug_gnu_pubtypes contents: 223; CHECK: Offset Linkage Kind Name 224; CHECK-DAG: [[C]] EXTERNAL TYPE "C" 225; CHECK-DAG: [[D]] EXTERNAL TYPE "ns::D" 226; CHECK-DAG: [[INT]] STATIC TYPE "int" 227 228source_filename = "test/DebugInfo/X86/gnu-public-names.ll" 229 230%struct.C = type { i8 } 231%"struct.ns::D" = type { i32 } 232 233@_ZN1C22static_member_variableE = global i32 0, align 4, !dbg !0 234@global_variable = global %struct.C zeroinitializer, align 1, !dbg !22 235@_ZN2ns25global_namespace_variableE = global i32 1, align 4, !dbg !24 236@_ZN2ns1dE = global %"struct.ns::D" zeroinitializer, align 4, !dbg !26 237@_ZZ2f3vE1z = internal global i32 0, align 4, !dbg !28 238@_ZN12_GLOBAL__N_11iE = internal global i32 0, align 4, !dbg !34 239@_ZN12_GLOBAL__N_15inner1bE = internal global i32 0, align 4, !dbg !37 240@_ZN5outer12_GLOBAL__N_11cE = internal global i32 0, align 4, !dbg !40 241 242; Function Attrs: nounwind uwtable 243define void @_ZN1C15member_functionEv(%struct.C* %this) #0 align 2 !dbg !51 { 244entry: 245 %this.addr = alloca %struct.C*, align 8 246 store %struct.C* %this, %struct.C** %this.addr, align 8 247 call void @llvm.dbg.declare(metadata %struct.C** %this.addr, metadata !52, metadata !54), !dbg !55 248 %this1 = load %struct.C*, %struct.C** %this.addr 249 store i32 0, i32* @_ZN1C22static_member_variableE, align 4, !dbg !56 250 ret void, !dbg !57 251} 252 253; Function Attrs: nounwind readnone 254declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 255 256; Function Attrs: nounwind uwtable 257define i32 @_ZN1C22static_member_functionEv() #0 align 2 !dbg !58 { 258entry: 259 %0 = load i32, i32* @_ZN1C22static_member_variableE, align 4, !dbg !59 260 ret i32 %0, !dbg !59 261} 262 263; Function Attrs: nounwind uwtable 264define i32 @_Z15global_functionv() #0 !dbg !60 { 265entry: 266 ret i32 -1, !dbg !61 267} 268 269; Function Attrs: nounwind uwtable 270define void @_ZN2ns25global_namespace_functionEv() #0 !dbg !62 { 271entry: 272 call void @_ZN1C15member_functionEv(%struct.C* @global_variable), !dbg !65 273 ret void, !dbg !66 274} 275 276; Function Attrs: nounwind uwtable 277define i32* @_Z2f3v() #0 !dbg !30 { 278entry: 279 ret i32* @_ZZ2f3vE1z, !dbg !67 280} 281 282; Function Attrs: nounwind uwtable 283define i32 @_Z2f7v() #0 !dbg !68 { 284entry: 285 %0 = load i32, i32* @_ZN12_GLOBAL__N_11iE, align 4, !dbg !69 286 %call = call i32* @_Z2f3v(), !dbg !69 287 %1 = load i32, i32* %call, align 4, !dbg !69 288 %add = add nsw i32 %0, %1, !dbg !69 289 %2 = load i32, i32* @_ZN12_GLOBAL__N_15inner1bE, align 4, !dbg !69 290 %add1 = add nsw i32 %add, %2, !dbg !69 291 %3 = load i32, i32* @_ZN5outer12_GLOBAL__N_11cE, align 4, !dbg !69 292 %add2 = add nsw i32 %add1, %3, !dbg !69 293 ret i32 %add2, !dbg !69 294} 295 296attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" } 297attributes #1 = { nounwind readnone } 298 299!llvm.dbg.cu = !{!2} 300!llvm.module.flags = !{!48, !49} 301!llvm.ident = !{!50} 302 303!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 304!1 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !8) 305!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44, gnuPubnames: true) 306!3 = !DIFile(filename: "gnu-public-names.cpp", directory: "/tmp/dbginfo") 307!4 = !{} 308!5 = !{!6, !17} 309!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !3, line: 1, size: 8, align: 8, elements: !7, identifier: "_ZTS1C") 310!7 = !{!8, !10, !14} 311!8 = !DIDerivedType(tag: DW_TAG_member, name: "static_member_variable", scope: !6, file: !3, line: 4, baseType: !9, flags: DIFlagStaticMember) 312!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 313!10 = !DISubprogram(name: "member_function", linkageName: "_ZN1C15member_functionEv", scope: !6, file: !3, line: 2, type: !11, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false) 314!11 = !DISubroutineType(types: !12) 315!12 = !{null, !13} 316!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 317!14 = !DISubprogram(name: "static_member_function", linkageName: "_ZN1C22static_member_functionEv", scope: !6, file: !3, line: 3, type: !15, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false) 318!15 = !DISubroutineType(types: !16) 319!16 = !{!9} 320!17 = !DICompositeType(tag: DW_TAG_structure_type, name: "D", scope: !18, file: !3, line: 29, size: 32, align: 32, elements: !19, identifier: "_ZTSN2ns1DE") 321!18 = !DINamespace(name: "ns", scope: null) 322!19 = !{!20} 323!20 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !17, file: !3, line: 30, baseType: !9, size: 32, align: 32) 324!21 = !{!0, !22, !24, !26, !28, !34, !37, !40} 325!22 = !DIGlobalVariableExpression(var: !23, expr: !DIExpression()) 326!23 = !DIGlobalVariable(name: "global_variable", scope: !2, file: !3, line: 17, type: !6, isLocal: false, isDefinition: true) 327!24 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression()) 328!25 = !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !18, file: !3, line: 27, type: !9, isLocal: false, isDefinition: true) 329!26 = !DIGlobalVariableExpression(var: !27, expr: !DIExpression()) 330!27 = !DIGlobalVariable(name: "d", linkageName: "_ZN2ns1dE", scope: !18, file: !3, line: 31, type: !17, isLocal: false, isDefinition: true) 331!28 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression()) 332!29 = !DIGlobalVariable(name: "z", scope: !30, file: !3, line: 41, type: !9, isLocal: true, isDefinition: true) 333!30 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !3, file: !3, line: 40, type: !31, isLocal: false, isDefinition: true, scopeLine: 40, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 334!31 = !DISubroutineType(types: !32) 335!32 = !{!33} 336!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64) 337!34 = !DIGlobalVariableExpression(var: !35, expr: !DIExpression()) 338!35 = !DIGlobalVariable(name: "i", linkageName: "_ZN12_GLOBAL__N_11iE", scope: !36, file: !3, line: 37, type: !9, isLocal: true, isDefinition: true) 339!36 = !DINamespace(scope: null) 340!37 = !DIGlobalVariableExpression(var: !38, expr: !DIExpression()) 341!38 = !DIGlobalVariable(name: "b", linkageName: "_ZN12_GLOBAL__N_15inner1bE", scope: !39, file: !3, line: 47, type: !9, isLocal: true, isDefinition: true) 342!39 = !DINamespace(name: "inner", scope: !36) 343!40 = !DIGlobalVariableExpression(var: !41, expr: !DIExpression()) 344!41 = !DIGlobalVariable(name: "c", linkageName: "_ZN5outer12_GLOBAL__N_11cE", scope: !42, file: !3, line: 53, type: !9, isLocal: true, isDefinition: true) 345!42 = !DINamespace(scope: !43) 346!43 = !DINamespace(name: "outer", scope: null) 347!44 = !{!45, !47} 348!45 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !46, file:!3, line: 34) 349!46 = !DIGlobalVariable(name: "global_namespace_variable_decl", linkageName: "_ZN2ns30global_namespace_variable_declE", scope: !18, file: !3, line: 28, type: !9, isLocal: false, isDefinition: false) 350!47 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !43, entity: !42, file: !3, line: 43) 351!48 = !{i32 2, !"Dwarf Version", i32 4} 352!49 = !{i32 2, !"Debug Info Version", i32 3} 353!50 = !{!"clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)"} 354!51 = distinct !DISubprogram(name: "member_function", linkageName: "_ZN1C15member_functionEv", scope: !6, file: !3, line: 9, type: !11, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !2, declaration: !10, retainedNodes: !4) 355!52 = !DILocalVariable(name: "this", arg: 1, scope: !51, type: !53, flags: DIFlagArtificial | DIFlagObjectPointer) 356!53 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, align: 64) 357!54 = !DIExpression() 358!55 = !DILocation(line: 0, scope: !51) 359!56 = !DILocation(line: 10, scope: !51) 360!57 = !DILocation(line: 11, scope: !51) 361!58 = distinct !DISubprogram(name: "static_member_function", linkageName: "_ZN1C22static_member_functionEv", scope: !6, file: !3, line: 13, type: !15, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !2, declaration: !14, retainedNodes: !4) 362!59 = !DILocation(line: 14, scope: !58) 363!60 = distinct !DISubprogram(name: "global_function", linkageName: "_Z15global_functionv", scope: !3, file: !3, line: 19, type: !15, isLocal: false, isDefinition: true, scopeLine: 19, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 364!61 = !DILocation(line: 20, scope: !60) 365!62 = distinct !DISubprogram(name: "global_namespace_function", linkageName: "_ZN2ns25global_namespace_functionEv", scope: !18, file: !3, line: 24, type: !63, isLocal: false, isDefinition: true, scopeLine: 24, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 366!63 = !DISubroutineType(types: !64) 367!64 = !{null} 368!65 = !DILocation(line: 25, scope: !62) 369!66 = !DILocation(line: 26, scope: !62) 370!67 = !DILocation(line: 42, scope: !30) 371!68 = distinct !DISubprogram(name: "f7", linkageName: "_Z2f7v", scope: !3, file: !3, line: 57, type: !15, isLocal: false, isDefinition: true, scopeLine: 57, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 372!69 = !DILocation(line: 58, scope: !68) 373 374