• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: rm -rf %t
2 // Test that only forward declarations are emitted for types dfined in modules.
3 
4 // Modules:
5 // RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \
6 // RUN:     -dwarf-ext-refs -fmodules                                   \
7 // RUN:     -fmodule-format=obj -fimplicit-module-maps -DMODULES \
8 // RUN:     -triple %itanium_abi_triple \
9 // RUN:     -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t-mod.ll
10 // RUN: cat %t-mod.ll |  FileCheck %s
11 
12 // PCH:
13 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodule-format=obj -emit-pch -I%S/Inputs \
14 // RUN:     -triple %itanium_abi_triple \
15 // RUN:     -o %t.pch %S/Inputs/DebugCXX.h
16 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone \
17 // RUN:     -dwarf-ext-refs -fmodule-format=obj \
18 // RUN:     -triple %itanium_abi_triple \
19 // RUN:     -include-pch %t.pch %s -emit-llvm -o %t-pch.ll %s
20 // RUN: cat %t-pch.ll |  FileCheck %s
21 // RUN: cat %t-pch.ll |  FileCheck %s --check-prefix=CHECK-PCH
22 
23 #ifdef MODULES
24 @import DebugCXX;
25 #endif
26 
27 using DebugCXX::Struct;
28 
29 Struct s;
30 DebugCXX::Enum e;
31 
32 // Template instantiations.
33 DebugCXX::Template<long> implicitTemplate;
34 DebugCXX::Template<int> explicitTemplate;
35 DebugCXX::FloatInstantiation typedefTemplate;
36 DebugCXX::B anchoredTemplate;
37 
38 int Struct::static_member = -1;
39 enum {
40   e3 = -1
41 } conflicting_uid = e3;
42 auto anon_enum = DebugCXX::e2;
43 char _anchor = anon_enum + conflicting_uid;
44 
45 TypedefUnion tdu;
46 TypedefEnum tde;
47 TypedefStruct tds;
48 TypedefTemplate tdt;
49 Template1<int> explicitTemplate1;
50 
51 template <class T> class FwdDeclTemplate { T t; };
52 TypedefFwdDeclTemplate tdfdt;
53 
54 InAnonymousNamespace anon;
55 
56 // Types that are forward-declared in the module and defined here.
57 struct PureFwdDecl { int i; };
58 PureFwdDecl definedLocally;
59 
60 struct Specialized<int>::Member { int i; };
61 struct Specialized<int>::Member definedLocally2;
62 
63 template <class T> struct FwdDeclTemplateMember<T>::Member { T t; };
64 TypedefFwdDeclTemplateMember tdfdtm;
65 
foo()66 void foo() {
67   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
68 }
69 
70 
71 // CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
72 // CHECK-SAME:             scope: ![[NS:[0-9]+]],
73 // CHECK-SAME:             flags: DIFlagFwdDecl,
74 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
75 
76 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
77 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
78 
79 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
80 // CHECK-SAME:             scope: ![[NS]],
81 // CHECK-SAME:             flags: DIFlagFwdDecl,
82 // CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
83 
84 // This type is anchored in the module by an explicit template instantiation.
85 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
86 // CHECK-SAME:             name: "Template<long, DebugCXX::traits<long> >",
87 // CHECK-SAME:             scope: ![[NS]],
88 // CHECK-SAME:             flags: DIFlagFwdDecl,
89 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
90 
91 // This type is anchored in the module by an explicit template instantiation.
92 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
93 // CHECK-SAME:             name: "Template<int, DebugCXX::traits<int> >",
94 // CHECK-SAME:             scope: ![[NS]],
95 // CHECK-SAME:             flags: DIFlagFwdDecl,
96 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
97 
98 // This type isn't, however, even with standalone non-module debug info this
99 // type is a forward declaration.
100 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
101 
102 // This one isn't.
103 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
104 // CHECK-SAME:             name: "Template<float, DebugCXX::traits<float> >",
105 // CHECK-SAME:             scope: ![[NS]],
106 // CHECK-SAME:             templateParams:
107 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
108 
109 // This type is anchored in the module by an explicit template instantiation.
110 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
111 // CHECK-SAME:             flags: DIFlagFwdDecl,
112 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6traitsIfEE")
113 
114 
115 // This type is anchored in the module by an explicit template instantiation.
116 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
117 // CHECK-SAME:             scope: ![[NS]],
118 // CHECK-SAME:             flags: DIFlagFwdDecl,
119 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX1AIJvEEE")
120 
121 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
122 // CHECK-SAME:           scope: ![[STRUCT]]
123 
124 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
125 // CHECK-SAME:             flags: DIFlagFwdDecl,
126 // CHECK-SAME:             identifier: "_ZTS12TypedefUnion")
127 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
128 // CHECK-SAME:             flags: DIFlagFwdDecl,
129 // CHECK-SAME:             identifier: "_ZTS11TypedefEnum")
130 // CHECK: !DICompositeType(tag: DW_TAG_structure_type,
131 // CHECK-SAME:             flags: DIFlagFwdDecl,
132 // CHECK-SAME:             identifier: "_ZTS13TypedefStruct")
133 
134 // This one isn't.
135 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
136 // CHECK-SAME:             templateParams:
137 // CHECK-SAME:             identifier: "_ZTS9Template1IPvE")
138 
139 // This type is anchored in the module by an explicit template instantiation.
140 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
141 // CHECK-SAME:             flags: DIFlagFwdDecl,
142 // CHECK-SAME:             identifier: "_ZTS9Template1IiE")
143 
144 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
145 // CHECK-SAME:             templateParams:
146 // CHECK-SAME:             identifier: "_ZTS15FwdDeclTemplateIiE")
147 
148 // This type is defined locally and forward-declared in the module.
149 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
150 // CHECK-SAME:             elements:
151 // CHECK-SAME:             identifier: "_ZTS11PureFwdDecl")
152 
153 // This type is defined locally and forward-declared in the module.
154 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
155 // CHECK-SAME:             elements:
156 // CHECK-SAME:             identifier: "_ZTSN11SpecializedIiE6MemberE")
157 
158 // This type is defined locally and forward-declared in the module.
159 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
160 // CHECK-SAME:             elements:
161 // CHECK-SAME:             identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
162 
163 
164 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
165 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
166 // CHECK-SAME:             line: 16
167 
168 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
169 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
170 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
171 // CHECK-SAME:                elements: !{{[0-9]+}})
172 // CHECK: !DIGlobalVariable(name: "GlobalStruct",
173 // CHECK-SAME:              type: ![[GLOBAL_STRUCT:[0-9]+]]
174 // CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
175 // CHECK-SAME:                elements: !{{[0-9]+}})
176 
177 
178 // CHECK: !DIGlobalVariable(name: "anon",
179 // CHECK-SAME:              type: ![[GLOBAL_ANON:[0-9]+]]
180 // CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
181 // CHECK-SAME:              name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
182 
183 
184 // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
185 
186 // CHECK: !DICompileUnit(
187 // CHECK-SAME:           splitDebugFilename:
188 // CHECK-SAME:           dwoId:
189 // CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
190 // CHECK-PCH:                dwoId: 18446744073709551614
191