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 5namespace A { 6#line 1 "foo.cpp" 7namespace B { 8extern int i; 9int f1() { return 0; } 10void f1(int) { } 11struct foo; 12struct bar { }; 13typedef bar baz; 14extern int var_decl; 15void func_decl(void); 16extern int var_fwd; 17void func_fwd(void); 18} 19} 20namespace A { 21using namespace B; 22} 23 24using namespace A; 25namespace E = A; 26int B::i = f1(); 27int 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 47namespace A { 48using B::i; 49namespace B { 50int var_fwd = i; 51} 52} 53void 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: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope: [[NS:![0-9]+]], 61// CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: [[FOOCPP:![0-9]+]], line: 1) 62// CHECK: [[FOOCPP]] = !DIFile(filename: "foo.cpp" 63// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-9]+]], line: 5) 64// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp", 65// CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name: "var_fwd",{{.*}} scope: [[NS]], 66// CHECK-SAME: line: 44 67// CHECK-SAME: isDefinition: true 68// 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]+]]} 69// CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CTXT]], entity: [[NS]], line: 15) 70 71// CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CU]], entity: [[CTXT]], 72// CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "E", scope: [[CU]], entity: [[CTXT]], line: 19) 73// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[LEX2:![0-9]+]], entity: [[NS]], line: 23) 74// CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: [[FOOCPP]], 75// CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: [[FOOCPP]], 76 77// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} isDefinition: true 78// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[FUNC]], entity: [[CTXT:![0-9]+]], 79// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FOO:![0-9]+]], line: 27) 80// CHECK: [[FOO]] = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", 81// CHECK-SAME: line: 5 82// CHECK-SAME: DIFlagFwdDecl 83// CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAR:![0-9]+]] 84// CHECK: [[BAR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", 85// CHECK-SAME: line: 6 86// CHECK-SAME: DIFlagFwdDecl 87 88// CHECK: [[M8]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[F1:![0-9]+]] 89// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4 90// CHECK-SAME: isDefinition: true 91// CHECK: [[M9]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[I]] 92// CHECK: [[M10]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAZ:![0-9]+]] 93// CHECK: [[BAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", scope: [[NS]], file: [[FOOCPP]], 94// CHECK-SAME: baseType: [[BAR]] 95// CHECK: [[M11]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "X", scope: [[FUNC]], entity: [[CTXT]] 96// CHECK: [[M12]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "Y", scope: [[FUNC]], entity: [[M11]] 97// CHECK: [[M13]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_DECL:![0-9]+]] 98// CHECK: [[VAR_DECL]] = !DIGlobalVariable(name: "var_decl", linkageName: "{{[^"]*var_decl[^"]*}}", scope: [[NS]],{{.*}} line: 8, 99// CHECK: [[M14]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_DECL:![0-9]+]] 100// CHECK: [[FUNC_DECL]] = !DISubprogram(name: "func_decl", 101// CHECK-SAME: scope: [[NS]], file: [[FOOCPP]], line: 9 102// CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_FWD:![0-9]+]] 103// CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_FWD:![0-9]+]] 104// CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 47,{{.*}} isDefinition: true 105// CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[CTXT]], entity: [[I]] 106 107// CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit( 108// CHECK-GMLT-SAME: emissionKind: LineTablesOnly, 109// CHECK-GMLT-NOT: imports: 110 111// CHECK-NOLIMIT: !DICompositeType(tag: DW_TAG_structure_type, name: "bar",{{.*}} line: 6, 112// CHECK-NOLIMIT-NOT: DIFlagFwdDecl 113// CHECK-NOLIMIT-SAME: ){{$}} 114