blob: 592612b9a5db88ea0acb69b47fec8af9b2a3a06d [file] [log] [blame]
Adrian Prantl5c8bd882015-09-11 17:23:08 +00001// RUN: rm -rf %t
Adrian Prantl5e304902016-08-22 22:38:18 +00002// Test that only forward declarations are emitted for types defined in modules.
Adrian Prantl5c8bd882015-09-11 17:23:08 +00003
4// Modules:
Adrian Prantl05fefa42016-04-25 20:52:40 +00005// RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \
Adrian Prantle1c2ad82016-01-22 18:46:40 +00006// RUN: -dwarf-ext-refs -fmodules \
Adrian Prantl5c8bd882015-09-11 17:23:08 +00007// RUN: -fmodule-format=obj -fimplicit-module-maps -DMODULES \
Reid Kleckner854a2b72015-09-11 17:50:14 +00008// RUN: -triple %itanium_abi_triple \
Adrian Prantl5c8bd882015-09-11 17:23:08 +00009// 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 \
Reid Kleckner854a2b72015-09-11 17:50:14 +000014// RUN: -triple %itanium_abi_triple \
Adrian Prantl5c8bd882015-09-11 17:23:08 +000015// RUN: -o %t.pch %S/Inputs/DebugCXX.h
Adrian Prantl05fefa42016-04-25 20:52:40 +000016// RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone \
Adrian Prantle1c2ad82016-01-22 18:46:40 +000017// RUN: -dwarf-ext-refs -fmodule-format=obj \
Reid Kleckner854a2b72015-09-11 17:50:14 +000018// RUN: -triple %itanium_abi_triple \
Aaron Ballmand57e29f2017-04-14 17:37:29 +000019// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll
Adrian Prantl5c8bd882015-09-11 17:23:08 +000020// RUN: cat %t-pch.ll | FileCheck %s
Adrian Prantlae108c42016-01-22 18:46:45 +000021// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK-PCH
Adrian Prantle1c2ad82016-01-22 18:46:40 +000022
Adrian Prantl5c8bd882015-09-11 17:23:08 +000023#ifdef MODULES
24@import DebugCXX;
25#endif
26
27using DebugCXX::Struct;
28
29Struct s;
30DebugCXX::Enum e;
Adrian Prantl0dabc2a2016-04-26 23:37:38 +000031
32// Template instantiations.
Adrian Prantl5c8bd882015-09-11 17:23:08 +000033DebugCXX::Template<long> implicitTemplate;
34DebugCXX::Template<int> explicitTemplate;
Adrian Prantl05fefa42016-04-25 20:52:40 +000035DebugCXX::FloatInstantiation typedefTemplate;
36DebugCXX::B anchoredTemplate;
37
Adrian Prantl5c8bd882015-09-11 17:23:08 +000038int Struct::static_member = -1;
39enum {
40 e3 = -1
41} conflicting_uid = e3;
42auto anon_enum = DebugCXX::e2;
43char _anchor = anon_enum + conflicting_uid;
44
Adrian Prantle5238d22016-01-19 18:02:47 +000045TypedefUnion tdu;
46TypedefEnum tde;
47TypedefStruct tds;
Adrian Prantl05fefa42016-04-25 20:52:40 +000048TypedefTemplate tdt;
49Template1<int> explicitTemplate1;
50
51template <class T> class FwdDeclTemplate { T t; };
52TypedefFwdDeclTemplate tdfdt;
Adrian Prantle5238d22016-01-19 18:02:47 +000053
Adrian Prantl8f55b662016-01-20 01:29:34 +000054InAnonymousNamespace anon;
55
Adrian Prantl0dabc2a2016-04-26 23:37:38 +000056// Types that are forward-declared in the module and defined here.
Adrian Prantl88d79172016-04-26 21:58:18 +000057struct PureFwdDecl { int i; };
58PureFwdDecl definedLocally;
59
Adrian Prantl90931c42016-04-26 21:58:23 +000060struct Specialized<int>::Member { int i; };
61struct Specialized<int>::Member definedLocally2;
62
Adrian Prantl0dabc2a2016-04-26 23:37:38 +000063template <class T> struct FwdDeclTemplateMember<T>::Member { T t; };
64TypedefFwdDeclTemplateMember tdfdtm;
65
Adrian Prantl26cb1d22016-08-17 18:27:24 +000066SpecializedBase definedLocally3;
67extern template class WithSpecializedBase<int>;
68WithSpecializedBase<int> definedLocally4;
69
Adrian Prantlcd975012016-01-19 23:42:44 +000070void foo() {
Adrian Prantl8f55b662016-01-20 01:29:34 +000071 anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
Adrian Prantla43acdc2017-07-24 23:48:51 +000072 A a;
73 Virtual virt;
Adrian Prantlcd975012016-01-19 23:42:44 +000074}
75
Adrian Prantl5649b0e2017-07-19 00:09:58 +000076// CHECK: ![[CPP:.*]] = !DIFile(filename: {{.*}}ExtDebugInfo.cpp"
77
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +000078// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000079// CHECK-SAME: scope: ![[NS:[0-9]+]],
Adrian Prantl5c8bd882015-09-11 17:23:08 +000080// CHECK-SAME: flags: DIFlagFwdDecl,
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +000081// CHECK-SAME: identifier: "_ZTSN8DebugCXX4EnumE")
Adrian Prantl5c8bd882015-09-11 17:23:08 +000082
Adrian Prantl6ee72d72017-04-28 22:25:53 +000083// CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]])
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000084// CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
85
Adrian Prantlba6fdc52018-10-24 00:06:02 +000086// This type is not anchored in the module by an explicit template instantiation.
Adrian Prantl05fefa42016-04-25 20:52:40 +000087// CHECK: !DICompositeType(tag: DW_TAG_class_type,
88// CHECK-SAME: name: "Template<long, DebugCXX::traits<long> >",
89// CHECK-SAME: scope: ![[NS]],
Adrian Prantlba6fdc52018-10-24 00:06:02 +000090// CHECK-SAME: elements:
Adrian Prantl05fefa42016-04-25 20:52:40 +000091// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
92
93// This type is anchored in the module by an explicit template instantiation.
94// CHECK: !DICompositeType(tag: DW_TAG_class_type,
95// CHECK-SAME: name: "Template<int, DebugCXX::traits<int> >",
Adrian Prantl5c8bd882015-09-11 17:23:08 +000096// CHECK-SAME: scope: ![[NS]],
97// CHECK-SAME: flags: DIFlagFwdDecl,
98// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
99
Adrian Prantl05fefa42016-04-25 20:52:40 +0000100// This type isn't, however, even with standalone non-module debug info this
101// type is a forward declaration.
102// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
103
104// This one isn't.
105// CHECK: !DICompositeType(tag: DW_TAG_class_type,
106// CHECK-SAME: name: "Template<float, DebugCXX::traits<float> >",
107// CHECK-SAME: scope: ![[NS]],
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000108// CHECK-SAME: elements:
Adrian Prantl05fefa42016-04-25 20:52:40 +0000109// CHECK-SAME: templateParams:
110// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
111
112// This type is anchored in the module by an explicit template instantiation.
113// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
114// CHECK-SAME: flags: DIFlagFwdDecl,
115// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
116
117
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000118// This type is anchored in the module via a function argument,
119// but we don't know this (yet).
Adrian Prantl05fefa42016-04-25 20:52:40 +0000120// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000121// CHECK-SAME: scope: ![[NS]],
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000122// CHECK-SAME: elements:
Adrian Prantl05fefa42016-04-25 20:52:40 +0000123// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000124
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000125// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
Peter Collingbourneeeb56ab2016-09-13 01:13:19 +0000126// CHECK-SAME: scope: ![[STRUCT:[0-9]*]]
127
128// CHECK: ![[STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
129// CHECK-SAME: scope: ![[NS]],
130// CHECK-SAME: flags: DIFlagFwdDecl,
131// CHECK-SAME: identifier: "_ZTSN8DebugCXX6StructE")
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000132
Adrian Prantle5238d22016-01-19 18:02:47 +0000133// CHECK: !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000134// CHECK-SAME: flags: DIFlagFwdDecl,
135// CHECK-SAME: identifier: "_ZTS12TypedefUnion")
Adrian Prantle5238d22016-01-19 18:02:47 +0000136// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000137// CHECK-SAME: flags: DIFlagFwdDecl,
138// CHECK-SAME: identifier: "_ZTS11TypedefEnum")
Adrian Prantle5238d22016-01-19 18:02:47 +0000139// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000140// CHECK-SAME: flags: DIFlagFwdDecl,
141// CHECK-SAME: identifier: "_ZTS13TypedefStruct")
142
143// This one isn't.
144// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000145// CHECK-SAME: elements:
Adrian Prantl05fefa42016-04-25 20:52:40 +0000146// CHECK-SAME: templateParams:
147// CHECK-SAME: identifier: "_ZTS9Template1IPvE")
148
149// This type is anchored in the module by an explicit template instantiation.
150// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
151// CHECK-SAME: flags: DIFlagFwdDecl,
152// CHECK-SAME: identifier: "_ZTS9Template1IiE")
153
154// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000155// CHECK-SAME: elements:
Adrian Prantl05fefa42016-04-25 20:52:40 +0000156// CHECK-SAME: templateParams:
157// CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
Adrian Prantle5238d22016-01-19 18:02:47 +0000158
Adrian Prantl90931c42016-04-26 21:58:23 +0000159// This type is defined locally and forward-declared in the module.
Adrian Prantl88d79172016-04-26 21:58:18 +0000160// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
161// CHECK-SAME: elements:
162// CHECK-SAME: identifier: "_ZTS11PureFwdDecl")
163
Adrian Prantl90931c42016-04-26 21:58:23 +0000164// This type is defined locally and forward-declared in the module.
165// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
166// CHECK-SAME: elements:
167// CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE")
168
Adrian Prantl0dabc2a2016-04-26 23:37:38 +0000169// This type is defined locally and forward-declared in the module.
170// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
171// CHECK-SAME: elements:
172// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
173
Adrian Prantl26cb1d22016-08-17 18:27:24 +0000174// This type is defined locally and forward-declared in the module.
175// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "SpecializedBase",
176// CHECK-SAME: baseType: ![[SPECIALIZEDBASE:.*]])
177// CHECK: ![[SPECIALIZEDBASE]] =
178// CHECK-SAME: !DICompositeType(tag: DW_TAG_class_type,
179// CHECK-SAME: name: "WithSpecializedBase<float>",
180// CHECK-SAME: elements:
181// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIfE")
182
183// This type is explicitly specialized locally.
184// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "WithSpecializedBase<int>",
185// CHECK-SAME: elements:
186// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIiE")
Adrian Prantl0dabc2a2016-04-26 23:37:38 +0000187
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000188// CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
189// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
Adrian Prantlc5e36472018-01-03 19:10:21 +0000190// CHECK-SAME: line: 19
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000191
Adrian Prantl43e00812016-01-19 23:42:53 +0000192// CHECK: !DIGlobalVariable(name: "GlobalUnion",
193// CHECK-SAME: type: ![[GLOBAL_UNION:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000194// CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000195// CHECK-SAME: elements: !{{[0-9]+}})
196// CHECK: !DIGlobalVariable(name: "GlobalStruct",
197// CHECK-SAME: type: ![[GLOBAL_STRUCT:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000198// CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000199// CHECK-SAME: elements: !{{[0-9]+}})
200
Adrian Prantl05fefa42016-04-25 20:52:40 +0000201
Adrian Prantl8f55b662016-01-20 01:29:34 +0000202// CHECK: !DIGlobalVariable(name: "anon",
203// CHECK-SAME: type: ![[GLOBAL_ANON:[0-9]+]]
204// CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
205// CHECK-SAME: name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
206
207
Adrian Prantl5649b0e2017-07-19 00:09:58 +0000208// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !{{[0-9]+}}, entity: ![[STRUCT]], file: ![[CPP]], line: 27)
Adrian Prantlc96da8f2016-01-22 17:43:43 +0000209
210// CHECK: !DICompileUnit(
211// CHECK-SAME: splitDebugFilename:
212// CHECK-SAME: dwoId:
Adrian Prantld4e73e72016-01-22 19:14:24 +0000213// CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
214// CHECK-PCH: dwoId: 18446744073709551614
Adrian Prantla43acdc2017-07-24 23:48:51 +0000215
216// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
217// CHECK-SAME: DIFlagFwdDecl, identifier: "_ZTS1A")
218
219// There is a full definition of the type available in the module.
220// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
221// CHECK-SAME: DIFlagFwdDecl, identifier: "_ZTS7Virtual")