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 DebugCXX::Template<long> implicitTemplate;
32 DebugCXX::Template<int> explicitTemplate;
33 DebugCXX::FloatInstantiation typedefTemplate;
34 DebugCXX::B anchoredTemplate;
35 
36 int Struct::static_member = -1;
37 enum {
38   e3 = -1
39 } conflicting_uid = e3;
40 auto anon_enum = DebugCXX::e2;
41 char _anchor = anon_enum + conflicting_uid;
42 
43 TypedefUnion tdu;
44 TypedefEnum tde;
45 TypedefStruct tds;
46 TypedefTemplate tdt;
47 Template1<int> explicitTemplate1;
48 
49 template <class T> class FwdDeclTemplate { T t; };
50 TypedefFwdDeclTemplate tdfdt;
51 
52 InAnonymousNamespace anon;
53 
54 // Forward-declared in the module.
55 struct PureFwdDecl { int i; };
56 PureFwdDecl definedLocally;
57 
58 struct Specialized<int>::Member { int i; };
59 struct Specialized<int>::Member definedLocally2;
60 
61 void foo() {
62   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
63 }
64 
65 
66 // CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
67 // CHECK-SAME:             scope: ![[NS:[0-9]+]],
68 // CHECK-SAME:             flags: DIFlagFwdDecl,
69 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
70 
71 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
72 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
73 
74 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
75 // CHECK-SAME:             scope: ![[NS]],
76 // CHECK-SAME:             flags: DIFlagFwdDecl,
77 // CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
78 
79 // This type is anchored in the module by an explicit template instantiation.
80 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
81 // CHECK-SAME:             name: "Template<long, DebugCXX::traits<long> >",
82 // CHECK-SAME:             scope: ![[NS]],
83 // CHECK-SAME:             flags: DIFlagFwdDecl,
84 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
85 
86 // This type is anchored in the module by an explicit template instantiation.
87 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
88 // CHECK-SAME:             name: "Template<int, DebugCXX::traits<int> >",
89 // CHECK-SAME:             scope: ![[NS]],
90 // CHECK-SAME:             flags: DIFlagFwdDecl,
91 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
92 
93 // This type isn't, however, even with standalone non-module debug info this
94 // type is a forward declaration.
95 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
96 
97 // This one isn't.
98 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
99 // CHECK-SAME:             name: "Template<float, DebugCXX::traits<float> >",
100 // CHECK-SAME:             scope: ![[NS]],
101 // CHECK-SAME:             templateParams:
102 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
103 
104 // This type is anchored in the module by an explicit template instantiation.
105 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
106 // CHECK-SAME:             flags: DIFlagFwdDecl,
107 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6traitsIfEE")
108 
109 
110 // This type is anchored in the module by an explicit template instantiation.
111 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
112 // CHECK-SAME:             scope: ![[NS]],
113 // CHECK-SAME:             flags: DIFlagFwdDecl,
114 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX1AIJvEEE")
115 
116 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
117 // CHECK-SAME:           scope: ![[STRUCT]]
118 
119 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
120 // CHECK-SAME:             flags: DIFlagFwdDecl,
121 // CHECK-SAME:             identifier: "_ZTS12TypedefUnion")
122 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
123 // CHECK-SAME:             flags: DIFlagFwdDecl,
124 // CHECK-SAME:             identifier: "_ZTS11TypedefEnum")
125 // CHECK: !DICompositeType(tag: DW_TAG_structure_type,
126 // CHECK-SAME:             flags: DIFlagFwdDecl,
127 // CHECK-SAME:             identifier: "_ZTS13TypedefStruct")
128 
129 // This one isn't.
130 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
131 // CHECK-SAME:             templateParams:
132 // CHECK-SAME:             identifier: "_ZTS9Template1IPvE")
133 
134 // This type is anchored in the module by an explicit template instantiation.
135 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
136 // CHECK-SAME:             flags: DIFlagFwdDecl,
137 // CHECK-SAME:             identifier: "_ZTS9Template1IiE")
138 
139 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
140 // CHECK-SAME:             templateParams:
141 // CHECK-SAME:             identifier: "_ZTS15FwdDeclTemplateIiE")
142 
143 // This type is defined locally and forward-declared in the module.
144 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
145 // CHECK-SAME:             elements:
146 // CHECK-SAME:             identifier: "_ZTS11PureFwdDecl")
147 
148 // This type is defined locally and forward-declared in the module.
149 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
150 // CHECK-SAME:             elements:
151 // CHECK-SAME:             identifier: "_ZTSN11SpecializedIiE6MemberE")
152 
153 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
154 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
155 // CHECK-SAME:             line: 16
156 
157 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
158 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
159 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
160 // CHECK-SAME:                elements: !{{[0-9]+}})
161 // CHECK: !DIGlobalVariable(name: "GlobalStruct",
162 // CHECK-SAME:              type: ![[GLOBAL_STRUCT:[0-9]+]]
163 // CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
164 // CHECK-SAME:                elements: !{{[0-9]+}})
165 
166 
167 // CHECK: !DIGlobalVariable(name: "anon",
168 // CHECK-SAME:              type: ![[GLOBAL_ANON:[0-9]+]]
169 // CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
170 // CHECK-SAME:              name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
171 
172 
173 // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
174 
175 // CHECK: !DICompileUnit(
176 // CHECK-SAME:           splitDebugFilename:
177 // CHECK-SAME:           dwoId:
178 // CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
179 // CHECK-PCH:                dwoId: 18446744073709551614
180