blob: 4760737bc4ff25cf91ed5190adc00888f30fffe9 [file] [log] [blame]
Adrian Prantl5c8bd882015-09-11 17:23:08 +00001// RUN: rm -rf %t
2// Test that only forward declarations are emitted for types dfined in modules.
3
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 \
Adrian Prantl5c8bd882015-09-11 17:23:08 +000019// RUN: -include-pch %t.pch %s -emit-llvm -o %t-pch.ll %s
20// 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;
31DebugCXX::Template<long> implicitTemplate;
32DebugCXX::Template<int> explicitTemplate;
Adrian Prantl05fefa42016-04-25 20:52:40 +000033DebugCXX::FloatInstantiation typedefTemplate;
34DebugCXX::B anchoredTemplate;
35
Adrian Prantl5c8bd882015-09-11 17:23:08 +000036int Struct::static_member = -1;
37enum {
38 e3 = -1
39} conflicting_uid = e3;
40auto anon_enum = DebugCXX::e2;
41char _anchor = anon_enum + conflicting_uid;
42
Adrian Prantle5238d22016-01-19 18:02:47 +000043TypedefUnion tdu;
44TypedefEnum tde;
45TypedefStruct tds;
Adrian Prantl05fefa42016-04-25 20:52:40 +000046TypedefTemplate tdt;
47Template1<int> explicitTemplate1;
48
49template <class T> class FwdDeclTemplate { T t; };
50TypedefFwdDeclTemplate tdfdt;
Adrian Prantle5238d22016-01-19 18:02:47 +000051
Adrian Prantl8f55b662016-01-20 01:29:34 +000052InAnonymousNamespace anon;
53
Adrian Prantl88d79172016-04-26 21:58:18 +000054// Forward-declared in the module.
55struct PureFwdDecl { int i; };
56PureFwdDecl definedLocally;
57
Adrian Prantl90931c42016-04-26 21:58:23 +000058struct Specialized<int>::Member { int i; };
59struct Specialized<int>::Member definedLocally2;
60
Adrian Prantlcd975012016-01-19 23:42:44 +000061void foo() {
Adrian Prantl8f55b662016-01-20 01:29:34 +000062 anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
Adrian Prantlcd975012016-01-19 23:42:44 +000063}
64
Adrian Prantl05fefa42016-04-25 20:52:40 +000065
66// CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000067// CHECK-SAME: scope: ![[NS:[0-9]+]],
Adrian Prantl5c8bd882015-09-11 17:23:08 +000068// CHECK-SAME: flags: DIFlagFwdDecl,
69// CHECK-SAME: identifier: "_ZTSN8DebugCXX6StructE")
70
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000071// CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
72// CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
73
Adrian Prantl5c8bd882015-09-11 17:23:08 +000074// 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
Adrian Prantl05fefa42016-04-25 20:52:40 +000079// 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> >",
Adrian Prantl5c8bd882015-09-11 17:23:08 +000089// CHECK-SAME: scope: ![[NS]],
90// CHECK-SAME: flags: DIFlagFwdDecl,
91// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
92
Adrian Prantl05fefa42016-04-25 20:52:40 +000093// 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>",
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000112// CHECK-SAME: scope: ![[NS]],
113// CHECK-SAME: flags: DIFlagFwdDecl,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000114// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000115
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000116// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
117// CHECK-SAME: scope: ![[STRUCT]]
118
Adrian Prantle5238d22016-01-19 18:02:47 +0000119// CHECK: !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000120// CHECK-SAME: flags: DIFlagFwdDecl,
121// CHECK-SAME: identifier: "_ZTS12TypedefUnion")
Adrian Prantle5238d22016-01-19 18:02:47 +0000122// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000123// CHECK-SAME: flags: DIFlagFwdDecl,
124// CHECK-SAME: identifier: "_ZTS11TypedefEnum")
Adrian Prantle5238d22016-01-19 18:02:47 +0000125// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000126// 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")
Adrian Prantle5238d22016-01-19 18:02:47 +0000142
Adrian Prantl90931c42016-04-26 21:58:23 +0000143// This type is defined locally and forward-declared in the module.
Adrian Prantl88d79172016-04-26 21:58:18 +0000144// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
145// CHECK-SAME: elements:
146// CHECK-SAME: identifier: "_ZTS11PureFwdDecl")
147
Adrian Prantl90931c42016-04-26 21:58:23 +0000148// 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
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000153// 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
Adrian Prantl43e00812016-01-19 23:42:53 +0000157// CHECK: !DIGlobalVariable(name: "GlobalUnion",
158// CHECK-SAME: type: ![[GLOBAL_UNION:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000159// CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000160// CHECK-SAME: elements: !{{[0-9]+}})
161// CHECK: !DIGlobalVariable(name: "GlobalStruct",
162// CHECK-SAME: type: ![[GLOBAL_STRUCT:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000163// CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000164// CHECK-SAME: elements: !{{[0-9]+}})
165
Adrian Prantl05fefa42016-04-25 20:52:40 +0000166
Adrian Prantl8f55b662016-01-20 01:29:34 +0000167// 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
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000173// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
Adrian Prantlc96da8f2016-01-22 17:43:43 +0000174
175// CHECK: !DICompileUnit(
176// CHECK-SAME: splitDebugFilename:
177// CHECK-SAME: dwoId:
Adrian Prantld4e73e72016-01-22 19:14:24 +0000178// CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
179// CHECK-PCH: dwoId: 18446744073709551614