1; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -v - | FileCheck %s 2; CHECK: debug_info contents 3; CHECK: DW_AT_name{{.*}}= [[F1:.*]]) 4; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace 5; CHECK-NOT: DW_AT_decl_file 6; CHECK-NOT: DW_AT_decl_line 7; CHECK-NOT: NULL 8; CHECK: [[NS2:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace 9; CHECK-NEXT: DW_AT_name{{.*}} = "B" 10; CHECK-NOT: DW_AT_decl_file 11; CHECK-NOT: DW_AT_decl_line 12; CHECK-NOT: NULL 13; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable 14; CHECK-NEXT: DW_AT_name{{.*}}= "i" 15; CHECK: [[VAR_FWD:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable 16; CHECK-NEXT: DW_AT_name{{.*}}= "var_fwd" 17; CHECK-NOT: NULL 18; CHECK: [[FOO:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type 19; CHECK-NEXT: DW_AT_name{{.*}}= "foo" 20; CHECK-NEXT: DW_AT_declaration 21; CHECK-NOT: NULL 22; CHECK: [[BAR:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type 23; CHECK-NEXT: DW_AT_name{{.*}}= "bar" 24; CHECK: DW_TAG_subprogram 25; CHECK-NOT: DW_TAG 26; CHECK: DW_AT_MIPS_linkage_name 27; CHECK-NOT: DW_TAG 28; CHECK: DW_AT_name{{.*}}= "f1" 29; CHECK: [[FUNC1:.*]]: DW_TAG_subprogram 30; CHECK-NOT: DW_TAG 31; CHECK: DW_AT_MIPS_linkage_name 32; CHECK-NOT: DW_TAG 33; CHECK: DW_AT_name{{.*}}= "f1" 34; CHECK: [[BAZ:0x[0-9a-f]*]]:{{.*}}DW_TAG_typedef 35; CHECK-NOT: DW_TAG 36; CHECK: DW_AT_name{{.*}}= "baz" 37; CHECK: [[VAR_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_variable 38; CHECK-NOT: DW_TAG 39; CHECK: DW_AT_name{{.*}}= "var_decl" 40; CHECK-NOT: DW_TAG 41; CHECK: DW_AT_declaration 42; CHECK: [[FUNC_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram 43; CHECK-NOT: DW_TAG 44; CHECK: DW_AT_name{{.*}}= "func_decl" 45; CHECK-NOT: DW_TAG 46; CHECK: DW_AT_declaration 47; CHECK: [[FUNC_FWD:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram 48; CHECK-NOT: DW_TAG 49; CHECK: DW_AT_name{{.*}}= "func_fwd" 50; CHECK-NOT: DW_AT_declaration 51; CHECK: NULL 52 53; CHECK-NOT: NULL 54; CHECK: DW_TAG_imported_module 55; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:.*]]) 56; CHECK-NEXT: DW_AT_decl_line{{.*}}(15) 57; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]}) 58; CHECK: NULL 59; CHECK-NOT: NULL 60 61; CHECK: DW_TAG_imported_module 62; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:.*]]) 63; CHECK-NEXT: DW_AT_decl_line{{.*}}(18) 64; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) 65; CHECK-NOT: NULL 66 67; CHECK: DW_TAG_subprogram 68; CHECK-NOT: {{DW_TAG|NULL}} 69; CHECK: DW_TAG_subprogram 70; CHECK-NOT: DW_TAG 71; CHECK: DW_AT_MIPS_linkage_name 72; CHECK-NOT: DW_TAG 73; CHECK: DW_AT_name{{.*}}= "func" 74; CHECK-NOT: NULL 75; CHECK: DW_TAG_imported_module 76; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:.*]]) 77; CHECK-NEXT: DW_AT_decl_line{{.*}}(26) 78; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) 79; CHECK-NOT: NULL 80; CHECK: DW_TAG_imported_declaration 81; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 82; CHECK-NEXT: DW_AT_decl_line{{.*}}(27) 83; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FOO]]}) 84; CHECK-NOT: NULL 85; CHECK: DW_TAG_imported_declaration 86; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 87; CHECK-NEXT: DW_AT_decl_line{{.*}}(28) 88; CHECK-NEXT: DW_AT_import{{.*}}=> {[[BAR]]}) 89; CHECK-NOT: NULL 90; CHECK: DW_TAG_imported_declaration 91; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 92; CHECK-NEXT: DW_AT_decl_line{{.*}}(29) 93; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC1]]}) 94; CHECK-NOT: NULL 95; CHECK: DW_TAG_imported_declaration 96; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 97; CHECK-NEXT: DW_AT_decl_line{{.*}}(30) 98; CHECK-NEXT: DW_AT_import{{.*}}=> {[[I]]}) 99; CHECK-NOT: NULL 100; CHECK: DW_TAG_imported_declaration 101; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 102; CHECK-NEXT: DW_AT_decl_line{{.*}}(31) 103; CHECK-NEXT: DW_AT_import{{.*}}=> {[[BAZ]]}) 104; CHECK-NOT: NULL 105; CHECK: [[X:0x[0-9a-f]*]]:{{ *}}DW_TAG_imported_declaration 106; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 107; CHECK-NEXT: DW_AT_decl_line{{.*}}(32) 108; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]}) 109; CHECK-NEXT: DW_AT_name{{.*}}"X" 110; CHECK-NOT: NULL 111; CHECK: DW_TAG_imported_declaration 112; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 113; CHECK-NEXT: DW_AT_decl_line{{.*}}(33) 114; CHECK-NEXT: DW_AT_import{{.*}}=> {[[X]]}) 115; CHECK-NEXT: DW_AT_name{{.*}}"Y" 116; CHECK-NOT: NULL 117; CHECK: DW_TAG_imported_declaration 118; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 119; CHECK-NEXT: DW_AT_decl_line{{.*}}(34) 120; CHECK-NEXT: DW_AT_import{{.*}}=> {[[VAR_DECL]]}) 121; CHECK: DW_TAG_imported_declaration 122; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 123; CHECK-NEXT: DW_AT_decl_line{{.*}}(35) 124; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC_DECL]]}) 125; CHECK: DW_TAG_imported_declaration 126; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 127; CHECK-NEXT: DW_AT_decl_line{{.*}}(36) 128; CHECK-NEXT: DW_AT_import{{.*}}=> {[[VAR_FWD]]}) 129; CHECK: DW_TAG_imported_declaration 130; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 131; CHECK-NEXT: DW_AT_decl_line{{.*}}(37) 132; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC_FWD]]}) 133 134; CHECK: DW_TAG_lexical_block 135; CHECK-NOT: NULL 136; CHECK: DW_TAG_imported_module 137; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]]) 138; CHECK-NEXT: DW_AT_decl_line{{.*}}(23) 139; CHECK-NEXT: DW_AT_import{{.*}}=> 140; CHECK: NULL 141; CHECK: NULL 142; CHECK: NULL 143 144; IR generated from clang/test/CodeGenCXX/debug-info-namespace.cpp, file paths 145; changed to protect the guilty. The C++ source code is: 146; // RUN... 147; // RUN... 148; // RUN... 149; 150; namespace A { 151; #line 1 "foo.cpp" 152; namespace B { 153; extern int i; 154; int f1() { return 0; } 155; void f1(int) { } 156; struct foo; 157; struct bar { }; 158; typedef bar baz; 159; extern int var_decl; 160; void func_decl(void); 161; extern int var_fwd; 162; void func_fwd(void); 163; } 164; } 165; namespace A { 166; using namespace B; 167; } 168; 169; using namespace A; 170; namespace E = A; 171; int B::i = f1(); 172; int func(bool b) { 173; if (b) { 174; using namespace A::B; 175; return i; 176; } 177; using namespace A; 178; using B::foo; 179; using B::bar; 180; using B::f1; 181; using B::i; 182; using B::baz; 183; namespace X = A; 184; namespace Y = X; 185; using B::var_decl; 186; using B::func_decl; 187; using B::var_fwd; 188; using B::func_fwd; 189; return i + X::B::i + Y::B::i; 190; } 191; 192; namespace A { 193; using B::i; 194; namespace B { 195; int var_fwd = i; 196; } 197; } 198; void B::func_fwd() {} 199 200@_ZN1A1B1iE = global i32 0, align 4, !dbg !131 201@_ZN1A1B7var_fwdE = global i32 0, align 4, !dbg !132 202@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_debug_info_namespace.cpp, i8* null }] 203 204; Function Attrs: nounwind ssp uwtable 205define i32 @_ZN1A1B2f1Ev() #0 !dbg !10 { 206entry: 207 ret i32 0, !dbg !60 208} 209 210; Function Attrs: nounwind ssp uwtable 211define void @_ZN1A1B2f1Ei(i32) #0 !dbg !14 { 212entry: 213 %.addr = alloca i32, align 4 214 store i32 %0, i32* %.addr, align 4 215 call void @llvm.dbg.declare(metadata i32* %.addr, metadata !61, metadata !62), !dbg !63 216 ret void, !dbg !64 217} 218 219; Function Attrs: nounwind readnone 220declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 221 222define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" !dbg !17 { 223entry: 224 %call = call i32 @_ZN1A1B2f1Ev(), !dbg !65 225 store i32 %call, i32* @_ZN1A1B1iE, align 4, !dbg !65 226 ret void, !dbg !65 227} 228 229; Function Attrs: nounwind ssp uwtable 230define i32 @_Z4funcb(i1 zeroext %b) #0 !dbg !21 { 231entry: 232 %retval = alloca i32, align 4 233 %b.addr = alloca i8, align 1 234 %frombool = zext i1 %b to i8 235 store i8 %frombool, i8* %b.addr, align 1 236 call void @llvm.dbg.declare(metadata i8* %b.addr, metadata !66, metadata !62), !dbg !67 237 %0 = load i8, i8* %b.addr, align 1, !dbg !68 238 %tobool = trunc i8 %0 to i1, !dbg !68 239 br i1 %tobool, label %if.then, label %if.end, !dbg !68 240 241if.then: ; preds = %entry 242 %1 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !69 243 store i32 %1, i32* %retval, !dbg !69 244 br label %return, !dbg !69 245 246if.end: ; preds = %entry 247 %2 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70 248 %3 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70 249 %add = add nsw i32 %2, %3, !dbg !70 250 %4 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70 251 %add1 = add nsw i32 %add, %4, !dbg !70 252 store i32 %add1, i32* %retval, !dbg !70 253 br label %return, !dbg !70 254 255return: ; preds = %if.end, %if.then 256 %5 = load i32, i32* %retval, !dbg !71 257 ret i32 %5, !dbg !71 258} 259 260define internal void @__cxx_global_var_init1() section "__TEXT,__StaticInit,regular,pure_instructions" !dbg !25 { 261entry: 262 %0 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !72 263 store i32 %0, i32* @_ZN1A1B7var_fwdE, align 4, !dbg !72 264 ret void, !dbg !72 265} 266 267; Function Attrs: nounwind ssp uwtable 268define void @_ZN1A1B8func_fwdEv() #0 !dbg !26 { 269entry: 270 ret void, !dbg !73 271} 272 273define internal void @_GLOBAL__sub_I_debug_info_namespace.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" { 274entry: 275 call void @__cxx_global_var_init(), !dbg !74 276 call void @__cxx_global_var_init1(), !dbg !74 277 ret void, !dbg !74 278} 279 280attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 281attributes #1 = { nounwind readnone } 282 283!llvm.dbg.cu = !{!0} 284!llvm.module.flags = !{!57, !58} 285!llvm.ident = !{!59} 286 287!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !3, globals: !30, imports: !33) 288!1 = !DIFile(filename: "debug-info-namespace.cpp", directory: "/tmp") 289!2 = !{} 290!3 = !{!4, !8} 291!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", line: 5, flags: DIFlagFwdDecl, file: !5, scope: !6, identifier: "_ZTSN1A1B3fooE") 292!5 = !DIFile(filename: "foo.cpp", directory: "/tmp") 293!6 = !DINamespace(name: "B", scope: !7) 294!7 = !DINamespace(name: "A", scope: null) 295!8 = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", line: 6, size: 8, align: 8, file: !5, scope: !6, elements: !2, identifier: "_ZTSN1A1B3barE") 296!10 = distinct !DISubprogram(name: "f1", linkageName: "_ZN1A1B2f1Ev", line: 3, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !5, scope: !6, type: !11, retainedNodes: !2) 297!11 = !DISubroutineType(types: !12) 298!12 = !{!13} 299!13 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 300!14 = distinct !DISubprogram(name: "f1", linkageName: "_ZN1A1B2f1Ei", line: 4, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !5, scope: !6, type: !15, retainedNodes: !2) 301!15 = !DISubroutineType(types: !16) 302!16 = !{null, !13} 303!17 = distinct !DISubprogram(name: "__cxx_global_var_init", line: 20, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 20, file: !5, scope: !18, type: !19, retainedNodes: !2) 304!18 = !DIFile(filename: "foo.cpp", directory: "/tmp") 305!19 = !DISubroutineType(types: !20) 306!20 = !{null} 307!21 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcb", line: 21, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 21, file: !5, scope: !18, type: !22, retainedNodes: !2) 308!22 = !DISubroutineType(types: !23) 309!23 = !{!13, !24} 310!24 = !DIBasicType(tag: DW_TAG_base_type, name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean) 311!25 = distinct !DISubprogram(name: "__cxx_global_var_init1", line: 44, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 44, file: !5, scope: !18, type: !19, retainedNodes: !2) 312!26 = distinct !DISubprogram(name: "func_fwd", linkageName: "_ZN1A1B8func_fwdEv", line: 47, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 47, file: !5, scope: !6, type: !19, retainedNodes: !2) 313!27 = distinct !DISubprogram(name: "", linkageName: "_GLOBAL__sub_I_debug_info_namespace.cpp", isLocal: true, isDefinition: true, flags: DIFlagArtificial, isOptimized: false, unit: !0, file: !1, scope: !28, type: !29, retainedNodes: !2) 314!28 = !DIFile(filename: "debug-info-namespace.cpp", directory: "/tmp") 315!29 = !DISubroutineType(types: !2) 316!30 = !{!131, !132} 317!31 = !DIGlobalVariable(name: "i", linkageName: "_ZN1A1B1iE", line: 20, isLocal: false, isDefinition: true, scope: !6, file: !18, type: !13) 318!32 = !DIGlobalVariable(name: "var_fwd", linkageName: "_ZN1A1B7var_fwdE", line: 44, isLocal: false, isDefinition: true, scope: !6, file: !18, type: !13) 319!33 = !{!34, !35, !36, !37, !40, !41, !42, !43, !44, !45, !47, !48, !49, !51, !54, !55, !56} 320!34 = !DIImportedEntity(tag: DW_TAG_imported_module, file: !5, line: 15, scope: !7, entity: !6) 321!35 = !DIImportedEntity(tag: DW_TAG_imported_module, file: !5, line: 18, scope: !0, entity: !7) 322!36 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 19, name: "E", scope: !0, entity: !7) 323!37 = !DIImportedEntity(tag: DW_TAG_imported_module, file: !5, line: 23, scope: !38, entity: !6) 324!38 = distinct !DILexicalBlock(line: 22, column: 10, file: !5, scope: !39) 325!39 = distinct !DILexicalBlock(line: 22, column: 7, file: !5, scope: !21) 326!40 = !DIImportedEntity(tag: DW_TAG_imported_module, file: !5, line: 26, scope: !21, entity: !7) 327!41 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 27, scope: !21, entity: !4) 328!42 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 28, scope: !21, entity: !8) 329!43 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 29, scope: !21, entity: !14) 330!44 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 30, scope: !21, entity: !31) 331!45 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 31, scope: !21, entity: !46) 332!46 = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", line: 7, file: !5, scope: !6, baseType: !8) 333!47 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 32, name: "X", scope: !21, entity: !7) 334!48 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 33, name: "Y", scope: !21, entity: !47) 335!49 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 34, scope: !21, entity: !50) 336!50 = !DIGlobalVariable(name: "var_decl", linkageName: "_ZN1A1B8var_declE", line: 8, isLocal: false, isDefinition: false, scope: !6, file: !18, type: !13) 337!51 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 35, scope: !21, entity: !52) 338!52 = !DISubprogram(name: "func_decl", linkageName: "_ZN1A1B9func_declEv", line: 9, isLocal: false, isDefinition: false, flags: DIFlagPrototyped, isOptimized: false, file: !5, scope: !6, type: !19, retainedNodes: !53) 339!53 = !{} ; previously: invalid DW_TAG_base_type 340!54 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 36, scope: !21, entity: !32) 341!55 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 37, scope: !21, entity: !26) 342!56 = !DIImportedEntity(tag: DW_TAG_imported_declaration, file: !5, line: 42, scope: !7, entity: !31) 343!57 = !{i32 2, !"Dwarf Version", i32 2} 344!58 = !{i32 2, !"Debug Info Version", i32 3} 345!59 = !{!"clang version 3.6.0 "} 346!60 = !DILocation(line: 3, column: 12, scope: !10) 347!61 = !DILocalVariable(name: "", line: 4, arg: 1, scope: !14, file: !18, type: !13) 348!62 = !DIExpression() 349!63 = !DILocation(line: 4, column: 12, scope: !14) 350!64 = !DILocation(line: 4, column: 16, scope: !14) 351!65 = !DILocation(line: 20, column: 12, scope: !17) 352!66 = !DILocalVariable(name: "b", line: 21, arg: 1, scope: !21, file: !18, type: !24) 353!67 = !DILocation(line: 21, column: 15, scope: !21) 354!68 = !DILocation(line: 22, column: 7, scope: !21) 355!69 = !DILocation(line: 24, column: 5, scope: !38) 356!70 = !DILocation(line: 38, column: 3, scope: !21) 357!71 = !DILocation(line: 39, column: 1, scope: !21) 358!72 = !DILocation(line: 44, column: 15, scope: !25) 359!73 = !DILocation(line: 47, column: 21, scope: !26) 360!74 = !DILocation(line: 0, scope: !75) 361!75 = !DILexicalBlockFile(discriminator: 0, file: !5, scope: !27) 362!131 = !DIGlobalVariableExpression(var: !31, expr: !DIExpression()) 363!132 = !DIGlobalVariableExpression(var: !32, expr: !DIExpression()) 364