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 void foo() {
59   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
60 }
61 
62 
63 // CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
64 // CHECK-SAME:             scope: ![[NS:[0-9]+]],
65 // CHECK-SAME:             flags: DIFlagFwdDecl,
66 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
67 
68 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
69 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
70 
71 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
72 // CHECK-SAME:             scope: ![[NS]],
73 // CHECK-SAME:             flags: DIFlagFwdDecl,
74 // CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
75 
76 // This type is anchored in the module by an explicit template instantiation.
77 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
78 // CHECK-SAME:             name: "Template<long, DebugCXX::traits<long> >",
79 // CHECK-SAME:             scope: ![[NS]],
80 // CHECK-SAME:             flags: DIFlagFwdDecl,
81 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
82 
83 // This type is anchored in the module by an explicit template instantiation.
84 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
85 // CHECK-SAME:             name: "Template<int, DebugCXX::traits<int> >",
86 // CHECK-SAME:             scope: ![[NS]],
87 // CHECK-SAME:             flags: DIFlagFwdDecl,
88 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
89 
90 // This type isn't, however, even with standalone non-module debug info this
91 // type is a forward declaration.
92 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
93 
94 // This one isn't.
95 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
96 // CHECK-SAME:             name: "Template<float, DebugCXX::traits<float> >",
97 // CHECK-SAME:             scope: ![[NS]],
98 // CHECK-SAME:             templateParams:
99 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
100 
101 // This type is anchored in the module by an explicit template instantiation.
102 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
103 // CHECK-SAME:             flags: DIFlagFwdDecl,
104 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6traitsIfEE")
105 
106 
107 // This type is anchored in the module by an explicit template instantiation.
108 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
109 // CHECK-SAME:             scope: ![[NS]],
110 // CHECK-SAME:             flags: DIFlagFwdDecl,
111 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX1AIJvEEE")
112 
113 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
114 // CHECK-SAME:           scope: ![[STRUCT]]
115 
116 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
117 // CHECK-SAME:             flags: DIFlagFwdDecl,
118 // CHECK-SAME:             identifier: "_ZTS12TypedefUnion")
119 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
120 // CHECK-SAME:             flags: DIFlagFwdDecl,
121 // CHECK-SAME:             identifier: "_ZTS11TypedefEnum")
122 // CHECK: !DICompositeType(tag: DW_TAG_structure_type,
123 // CHECK-SAME:             flags: DIFlagFwdDecl,
124 // CHECK-SAME:             identifier: "_ZTS13TypedefStruct")
125 
126 // This one isn't.
127 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
128 // CHECK-SAME:             templateParams:
129 // CHECK-SAME:             identifier: "_ZTS9Template1IPvE")
130 
131 // This type is anchored in the module by an explicit template instantiation.
132 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
133 // CHECK-SAME:             flags: DIFlagFwdDecl,
134 // CHECK-SAME:             identifier: "_ZTS9Template1IiE")
135 
136 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
137 // CHECK-SAME:             templateParams:
138 // CHECK-SAME:             identifier: "_ZTS15FwdDeclTemplateIiE")
139 
140 // This type is defined locally and forward-declare in the module.
141 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
142 // CHECK-SAME:             elements:
143 // CHECK-SAME:             identifier: "_ZTS11PureFwdDecl")
144 
145 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
146 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
147 // CHECK-SAME:             line: 16
148 
149 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
150 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
151 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
152 // CHECK-SAME:                elements: !{{[0-9]+}})
153 // CHECK: !DIGlobalVariable(name: "GlobalStruct",
154 // CHECK-SAME:              type: ![[GLOBAL_STRUCT:[0-9]+]]
155 // CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
156 // CHECK-SAME:                elements: !{{[0-9]+}})
157 
158 
159 // CHECK: !DIGlobalVariable(name: "anon",
160 // CHECK-SAME:              type: ![[GLOBAL_ANON:[0-9]+]]
161 // CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
162 // CHECK-SAME:              name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
163 
164 
165 // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
166 
167 // CHECK: !DICompileUnit(
168 // CHECK-SAME:           splitDebugFilename:
169 // CHECK-SAME:           dwoId:
170 // CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
171 // CHECK-PCH:                dwoId: 18446744073709551614
172