blob: cefb21eba2a0cca7aa48e2e96e23dd441003cc2e [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 Prantlcd975012016-01-19 23:42:44 +000054void foo() {
Adrian Prantl8f55b662016-01-20 01:29:34 +000055 anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
Adrian Prantlcd975012016-01-19 23:42:44 +000056}
57
Adrian Prantl05fefa42016-04-25 20:52:40 +000058
59// CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000060// CHECK-SAME: scope: ![[NS:[0-9]+]],
Adrian Prantl5c8bd882015-09-11 17:23:08 +000061// CHECK-SAME: flags: DIFlagFwdDecl,
62// CHECK-SAME: identifier: "_ZTSN8DebugCXX6StructE")
63
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +000064// CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
65// CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
66
Adrian Prantl5c8bd882015-09-11 17:23:08 +000067// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
68// CHECK-SAME: scope: ![[NS]],
69// CHECK-SAME: flags: DIFlagFwdDecl,
70// CHECK-SAME: identifier: "_ZTSN8DebugCXX4EnumE")
71
Adrian Prantl05fefa42016-04-25 20:52:40 +000072// This type is anchored in the module by an explicit template instantiation.
73// CHECK: !DICompositeType(tag: DW_TAG_class_type,
74// CHECK-SAME: name: "Template<long, DebugCXX::traits<long> >",
75// CHECK-SAME: scope: ![[NS]],
76// CHECK-SAME: flags: DIFlagFwdDecl,
77// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
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<int, DebugCXX::traits<int> >",
Adrian Prantl5c8bd882015-09-11 17:23:08 +000082// CHECK-SAME: scope: ![[NS]],
83// CHECK-SAME: flags: DIFlagFwdDecl,
84// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
85
Adrian Prantl05fefa42016-04-25 20:52:40 +000086// This type isn't, however, even with standalone non-module debug info this
87// type is a forward declaration.
88// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
89
90// This one isn't.
91// CHECK: !DICompositeType(tag: DW_TAG_class_type,
92// CHECK-SAME: name: "Template<float, DebugCXX::traits<float> >",
93// CHECK-SAME: scope: ![[NS]],
94// CHECK-SAME: templateParams:
95// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
96
97// This type is anchored in the module by an explicit template instantiation.
98// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
99// CHECK-SAME: flags: DIFlagFwdDecl,
100// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
101
102
103// This type is anchored in the module by an explicit template instantiation.
104// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000105// CHECK-SAME: scope: ![[NS]],
106// CHECK-SAME: flags: DIFlagFwdDecl,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000107// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000108
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000109// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
110// CHECK-SAME: scope: ![[STRUCT]]
111
Adrian Prantle5238d22016-01-19 18:02:47 +0000112// CHECK: !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000113// CHECK-SAME: flags: DIFlagFwdDecl,
114// CHECK-SAME: identifier: "_ZTS12TypedefUnion")
Adrian Prantle5238d22016-01-19 18:02:47 +0000115// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000116// CHECK-SAME: flags: DIFlagFwdDecl,
117// CHECK-SAME: identifier: "_ZTS11TypedefEnum")
Adrian Prantle5238d22016-01-19 18:02:47 +0000118// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl05fefa42016-04-25 20:52:40 +0000119// CHECK-SAME: flags: DIFlagFwdDecl,
120// CHECK-SAME: identifier: "_ZTS13TypedefStruct")
121
122// This one isn't.
123// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
124// CHECK-SAME: templateParams:
125// CHECK-SAME: identifier: "_ZTS9Template1IPvE")
126
127// This type is anchored in the module by an explicit template instantiation.
128// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
129// CHECK-SAME: flags: DIFlagFwdDecl,
130// CHECK-SAME: identifier: "_ZTS9Template1IiE")
131
132// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
133// CHECK-SAME: templateParams:
134// CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
Adrian Prantle5238d22016-01-19 18:02:47 +0000135
Adrian Prantl5c8bd882015-09-11 17:23:08 +0000136// CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
137// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
138// CHECK-SAME: line: 16
139
Adrian Prantl43e00812016-01-19 23:42:53 +0000140// CHECK: !DIGlobalVariable(name: "GlobalUnion",
141// CHECK-SAME: type: ![[GLOBAL_UNION:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000142// CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000143// CHECK-SAME: elements: !{{[0-9]+}})
144// CHECK: !DIGlobalVariable(name: "GlobalStruct",
145// CHECK-SAME: type: ![[GLOBAL_STRUCT:[0-9]+]]
Duncan P. N. Exon Smithf9521b02016-04-17 07:45:08 +0000146// CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
Adrian Prantl43e00812016-01-19 23:42:53 +0000147// CHECK-SAME: elements: !{{[0-9]+}})
148
Adrian Prantl05fefa42016-04-25 20:52:40 +0000149
Adrian Prantl8f55b662016-01-20 01:29:34 +0000150// CHECK: !DIGlobalVariable(name: "anon",
151// CHECK-SAME: type: ![[GLOBAL_ANON:[0-9]+]]
152// CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
153// CHECK-SAME: name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
154
155
Duncan P. N. Exon Smith383f8412016-04-23 21:08:27 +0000156// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
Adrian Prantlc96da8f2016-01-22 17:43:43 +0000157
158// CHECK: !DICompileUnit(
159// CHECK-SAME: splitDebugFilename:
160// CHECK-SAME: dwoId:
Adrian Prantld4e73e72016-01-22 19:14:24 +0000161// CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
162// CHECK-PCH: dwoId: 18446744073709551614