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