1 // RUN: %clang_cc1 -debug-info-kind=limited -S -emit-llvm %s -o - | FileCheck %s 2 // RUN: %clang_cc1 -debug-info-kind=line-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s 3 // RUN: %clang_cc1 -debug-info-kind=standalone -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s 4 5 namespace A { 6 #line 1 "foo.cpp" 7 namespace B { 8 extern int i; 9 int f1() { return 0; } 10 void f1(int) { } 11 struct foo; 12 struct bar { }; 13 typedef bar baz; 14 extern int var_decl; 15 void func_decl(void); 16 extern int var_fwd; 17 void func_fwd(void); 18 } 19 } 20 namespace A { 21 using namespace B; 22 } 23 24 using namespace A; 25 namespace E = A; 26 int B::i = f1(); 27 int func(bool b) { 28 if (b) { 29 using namespace A::B; 30 return i; 31 } 32 using namespace A; 33 using B::foo; 34 using B::bar; 35 using B::f1; 36 using B::i; 37 using B::baz; 38 namespace X = A; 39 namespace Y = X; 40 using B::var_decl; 41 using B::func_decl; 42 using B::var_fwd; 43 using B::func_fwd; 44 return i + X::B::i + Y::B::i; 45 } 46 47 namespace A { 48 using B::i; 49 namespace B { 50 int var_fwd = i; 51 } 52 } 53 void B::func_fwd() {} 54 55 // This should work even if 'i' and 'func' were declarations & not definitions, 56 // but it doesn't yet. 57 58 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit( 59 // CHECK-SAME: imports: [[MODULES:![0-9]*]] 60 // CHECK: [[FOO:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", 61 // CHECK-SAME: line: 5 62 // CHECK-SAME: DIFlagFwdDecl 63 // CHECK: [[FOOCPP:![0-9]+]] = !DIFile(filename: "foo.cpp" 64 // CHECK: [[NS:![0-9]+]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: [[FOOCPP]], line: 1) 65 // CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-9]+]], line: 5) 66 // CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp", 67 // CHECK: [[BAR:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", 68 // CHECK-SAME: line: 6 69 // CHECK-SAME: DIFlagFwdDecl 70 // CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4 71 // CHECK-SAME: isDefinition: true 72 // CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} isDefinition: true 73 // CHECK: [[FUNC_FWD:![0-9]+]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 47,{{.*}} isDefinition: true 74 // CHECK: [[I:![0-9]+]] = !DIGlobalVariable(name: "i",{{.*}} scope: [[NS]], 75 // CHECK: [[VAR_FWD:![0-9]+]] = !DIGlobalVariable(name: "var_fwd",{{.*}} scope: [[NS]], 76 // CHECK-SAME: line: 44 77 // CHECK-SAME: isDefinition: true 78 79 // CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], [[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], [[M17:![0-9]+]]} 80 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CTXT]], entity: [[NS]], line: 15) 81 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CU]], entity: [[CTXT]], 82 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "E", scope: [[CU]], entity: [[CTXT]], line: 19) 83 // CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[LEX2:![0-9]+]], entity: [[NS]], line: 23) 84 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: [[FOOCPP]], 85 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC]], file: [[FOOCPP]], 86 // CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[FUNC]], entity: [[CTXT]], 87 // CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FOO:!"_ZTSN1A1B3fooE"]], line: 27) 88 // CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAR:!"_ZTSN1A1B3barE"]] 89 // CHECK: [[M8]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[F1]] 90 // CHECK: [[M9]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[I]] 91 // CHECK: [[M10]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAZ:![0-9]+]] 92 // CHECK: [[BAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", scope: [[NS]], file: [[FOOCPP]], 93 // CHECK-SAME: baseType: !"_ZTSN1A1B3barE" 94 // CHECK: [[M11]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "X", scope: [[FUNC]], entity: [[CTXT]] 95 // CHECK: [[M12]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "Y", scope: [[FUNC]], entity: [[M11]] 96 // CHECK: [[M13]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_DECL:![0-9]+]] 97 // CHECK: [[VAR_DECL]] = !DIGlobalVariable(name: "var_decl", linkageName: "_ZN1A1B8var_declE", scope: [[NS]],{{.*}} line: 8, 98 // CHECK: [[M14]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_DECL:![0-9]+]] 99 // CHECK: [[FUNC_DECL]] = !DISubprogram(name: "func_decl", 100 // CHECK-SAME: scope: [[NS]], file: [[FOOCPP]], line: 9 101 // CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_FWD:![0-9]+]] 102 // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_FWD:![0-9]+]] 103 // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[CTXT]], entity: [[I]] 104 105 // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit( 106 // CHECK-GMLT-SAME: emissionKind: 2, 107 // CHECK-GMLT-NOT: imports: 108 109 // CHECK-NOLIMIT: !DICompositeType(tag: DW_TAG_structure_type, name: "bar",{{.*}} line: 6, 110 // CHECK-NOLIMIT-NOT: DIFlagFwdDecl 111 // CHECK-NOLIMIT-SAME: ){{$}} 112 113 // REQUIRES: dw2 114