Skip to content

Commit d54888a

Browse files
committed
[Modules] Refactor modules-ts tests to use standard c++ modules
We're going to remove the support for modules-ts. But there are a lot of tests which uses -fmodules-ts. We shouldn't remove them simply. This patch refactor these tests to use standard c++ modules.
1 parent fc6d517 commit d54888a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+588
-572
lines changed

clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm renamed to clang/test/CXX/module/basic/basic.def.odr/p4.cppm

+79-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
// RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s --implicit-check-not unused_inline --implicit-check-not unused_stastic_global_module
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %t/Module.cppm --implicit-check-not unused_inline --implicit-check-not unused_stastic_global_module
6+
//
7+
// RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple -emit-module-interface -o %t/Module.pcm
8+
// RUN: %clang_cc1 -std=c++20 %t/module.cpp -triple %itanium_abi_triple -fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp --implicit-check-not=unused --implicit-check-not=global_module
9+
//
10+
// RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple -fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp --implicit-check-not=unused --implicit-check-not=global_module
211

12+
//--- Module.cppm
313
// CHECK-DAG: @extern_var_global_module = external {{(dso_local )?}}global
414
// CHECK-DAG: @inline_var_global_module = linkonce_odr {{(dso_local )?}}global
515
// CHECK-DAG: @_ZL24static_var_global_module = internal global
@@ -19,12 +29,14 @@
1929
// can discard this global and its initializer (if any), and other TUs are not
2030
// permitted to run the initializer for this variable.
2131
// CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
22-
// CHECK-DAG: @_ZW6Module25static_var_module_linkage = {{(dso_local )?}}global
23-
// CHECK-DAG: @_ZW6Module24const_var_module_linkage = {{(dso_local )?}}constant
32+
// CHECK-DAG: @_ZL25static_var_module_linkage = internal
33+
// CHECK-DAG: @_ZL24const_var_module_linkage = internal
2434
//
2535
// CHECK-DAG: @_ZW6Module25unused_var_module_linkage = {{(dso_local )?}}global i32 4
26-
// CHECK-DAG: @_ZW6Module32unused_static_var_module_linkage = {{(dso_local )?}}global i32 5
27-
// CHECK-DAG: @_ZW6Module31unused_const_var_module_linkage = {{(dso_local )?}}constant i32 7
36+
// CHECK-NOT: @_ZW6Module32unused_static_var_module_linkage =
37+
// CHECK-NOT: @_ZW6Module31unused_const_var_module_linkage =
38+
39+
module;
2840

2941
static void unused_static_global_module() {}
3042
static void used_static_global_module() {}
@@ -73,12 +85,9 @@ export {
7385
}
7486
}
7587

76-
// FIXME: Ideally we wouldn't emit this as its name is not visible outside this
77-
// TU, but this module interface might contain a template that can use this
78-
// function so we conservatively emit it for now.
79-
// CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6Module28unused_static_module_linkagev
88+
// CHECK-NOT: define {{(dso_local )?}}void {{.*}}@_ZW6Module28unused_static_module_linkagev
8089
static void unused_static_module_linkage() {}
81-
// CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6Module26used_static_module_linkagev
90+
8291
static void used_static_module_linkage() {}
8392

8493
inline void unused_inline_module_linkage() {}
@@ -90,6 +99,7 @@ static int static_var_module_linkage;
9099
const int const_var_module_linkage = 3;
91100

92101
// CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6Module24noninline_module_linkagev
102+
// CHECK: define {{.*}}void {{.*}}@_ZL26used_static_module_linkagev
93103
void noninline_module_linkage() {
94104
used_static_module_linkage();
95105
// CHECK: define linkonce_odr {{.*}}@_ZW6Module26used_inline_module_linkagev
@@ -112,3 +122,62 @@ struct a {
112122
};
113123
// CHECK: define {{(dso_local )?}}void @_ZW6Module1fNS_1a1bENS0_1cE(
114124
void f(a::b, a::c) {}
125+
126+
//--- module.cpp
127+
128+
// CHECK-DAG: @_ZW6Module19extern_var_exported = external {{(dso_local )?}}global
129+
// CHECK-DAG: @_ZW6Module19inline_var_exported = linkonce_odr {{(dso_local )?}}global
130+
// CHECK-DAG: @_ZW6Module18const_var_exported = available_externally {{(dso_local )?}}constant i32 3,
131+
//
132+
// CHECK-DAG: @_ZW6Module25extern_var_module_linkage = external {{(dso_local )?}}global
133+
// CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
134+
// CHECK-DAG: @_ZL25static_var_module_linkage = internal {{(dso_local )?}}global i32 0,
135+
// CHECK-DAG: @_ZL24const_var_module_linkage = internal {{(dso_local )?}}constant i32 3,
136+
137+
module Module;
138+
139+
void use() {
140+
// CHECK: define linkonce_odr {{.*}}@_ZW6Module20used_inline_exportedv
141+
used_inline_exported();
142+
// CHECK: declare {{.*}}@_ZW6Module18noninline_exportedv
143+
noninline_exported();
144+
145+
(void)&extern_var_exported;
146+
(void)&inline_var_exported;
147+
(void)&const_var_exported;
148+
149+
// CHECK: define {{.*}}@_ZL26used_static_module_linkagev
150+
used_static_module_linkage();
151+
152+
// CHECK: define linkonce_odr {{.*}}@_ZW6Module26used_inline_module_linkagev
153+
used_inline_module_linkage();
154+
155+
// CHECK: declare {{.*}}@_ZW6Module24noninline_module_linkagev
156+
noninline_module_linkage();
157+
158+
(void)&extern_var_module_linkage;
159+
(void)&inline_var_module_linkage;
160+
(void)&static_var_module_linkage; // FIXME: Should not be visible here.
161+
(void)&const_var_module_linkage;
162+
}
163+
164+
//--- user.cpp
165+
166+
// CHECK-DAG: @_ZW6Module19extern_var_exported = external {{(dso_local )?}}global
167+
// CHECK-DAG: @_ZW6Module19inline_var_exported = linkonce_odr {{(dso_local )?}}global
168+
// CHECK-DAG: @_ZW6Module18const_var_exported = available_externally {{(dso_local )?}}constant i32 3
169+
170+
import Module;
171+
172+
void use() {
173+
// CHECK: define linkonce_odr {{.*}}@_ZW6Module20used_inline_exportedv
174+
used_inline_exported();
175+
// CHECK: declare {{.*}}@_ZW6Module18noninline_exportedv
176+
noninline_exported();
177+
178+
(void)&extern_var_exported;
179+
(void)&inline_var_exported;
180+
(void)&const_var_exported;
181+
182+
// Module-linkage declarations are not visible here.
183+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm
6+
// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm -DEXPORT
7+
// RUN: %clang_cc1 -std=c++20 -verify %t/global-vs-module.cppm -DUSING
8+
//
9+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/global-vs-module.cppm -o %t/M.pcm -DNO_GLOBAL -DEXPORT
10+
// RUN: %clang_cc1 -std=c++20 -verify %t/module-vs-global.cpp -fmodule-file=%t/M.pcm
11+
//
12+
// Some of the following tests intentionally have no -verify in their RUN
13+
// lines; we are testing that those cases do not produce errors.
14+
//
15+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/M.pcm -DMODULE_INTERFACE -verify
16+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/M.pcm -DMODULE_INTERFACE -DNO_IMPORT
17+
//
18+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/M.pcm -emit-module-interface -o %t/N.pcm -DMODULE_INTERFACE -DNO_ERRORS
19+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/N.pcm -verify
20+
// FIXME: Once we start importing "import" declarations properly, this should
21+
// be rejected (-verify should be added to the following line).
22+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/N.pcm -DNO_IMPORT
23+
//
24+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/M.pcm -emit-module-interface -o %t/N-no-M.pcm -DMODULE_INTERFACE -DNO_ERRORS -DNO_IMPORT
25+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/N-no-M.pcm -verify
26+
// RUN: %clang_cc1 -std=c++20 %t/module-vs-module.cpp -fmodule-file=%t/N-no-M.pcm -DNO_IMPORT
27+
28+
//--- global-vs-module.cppm
29+
#ifndef NO_GLOBAL
30+
module;
31+
extern int var; // expected-note {{previous declaration is here}}
32+
int func(); // expected-note {{previous declaration is here}}
33+
struct str; // expected-note {{previous declaration is here}}
34+
using type = int;
35+
36+
template<typename> extern int var_tpl; // expected-note {{previous declaration is here}}
37+
template<typename> int func_tpl(); // expected-note {{previous declaration is here}}
38+
template<typename> struct str_tpl; // expected-note {{previous declaration is here}}
39+
template<typename> using type_tpl = int; // expected-note {{previous declaration is here}}
40+
41+
typedef int type;
42+
namespace ns { using ::func; }
43+
namespace ns_alias = ns;
44+
#endif
45+
46+
export module M;
47+
48+
#ifdef USING
49+
using ::var;
50+
using ::func;
51+
using ::str;
52+
using ::type;
53+
using ::var_tpl;
54+
using ::func_tpl;
55+
using ::str_tpl;
56+
using ::type_tpl;
57+
#endif
58+
59+
#ifdef EXPORT
60+
export {
61+
#endif
62+
63+
extern int var; // expected-error {{declaration of 'var' in module M follows declaration in the global module}}
64+
int func(); // expected-error {{declaration of 'func' in module M follows declaration in the global module}}
65+
struct str; // expected-error {{declaration of 'str' in module M follows declaration in the global module}}
66+
using type = int;
67+
68+
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}}
69+
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}}
70+
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}}
71+
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}}
72+
73+
typedef int type;
74+
namespace ns { using ::func; }
75+
namespace ns_alias = ns;
76+
77+
#ifdef EXPORT
78+
}
79+
#endif
80+
81+
//--- module-vs-global.cpp
82+
import M;
83+
84+
extern int var; // expected-error {{declaration of 'var' in the global module follows declaration in module M}} [email protected]:35 {{previous}}
85+
int func(); // expected-error {{declaration of 'func' in the global module follows declaration in module M}} [email protected]:36 {{previous}}
86+
struct str; // expected-error {{declaration of 'str' in the global module follows declaration in module M}} [email protected]:37 {{previous}}
87+
using type = int;
88+
89+
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} [email protected]:40 {{previous}}
90+
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} [email protected]:41 {{previous}}
91+
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} [email protected]:42 {{previous}}
92+
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} [email protected]:43 {{previous}}
93+
94+
typedef int type;
95+
namespace ns { using ::func; }
96+
namespace ns_alias = ns;
97+
98+
//--- module-vs-module.cpp
99+
#ifdef MODULE_INTERFACE
100+
export module N;
101+
#else
102+
module N;
103+
#endif
104+
105+
#ifndef NO_IMPORT
106+
import M;
107+
#endif
108+
109+
#ifndef NO_ERRORS
110+
extern int var; // expected-error {{declaration of 'var' in module N follows declaration in module M}} [email protected]:35 {{previous}}
111+
int func(); // expected-error {{declaration of 'func' in module N follows declaration in module M}} [email protected]:36 {{previous}}
112+
struct str; // expected-error {{declaration of 'str' in module N follows declaration in module M}} [email protected]:37 {{previous}}
113+
using type = int;
114+
115+
template<typename> extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} [email protected]:40 {{previous}}
116+
template<typename> int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} [email protected]:41 {{previous}}
117+
template<typename> struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} [email protected]:42 {{previous}}
118+
template<typename> using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} [email protected]:43 {{previous}}
119+
120+
typedef int type;
121+
namespace ns { using ::func; }
122+
namespace ns_alias = ns;
123+
#endif
124+

clang/test/CXX/modules-ts/basic/basic.link/module-declaration.cpp renamed to clang/test/CXX/module/basic/basic.link/module-declaration.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
// Tests for module-declaration syntax.
22
//
33
// RUN: rm -rf %t
4-
// RUN: mkdir -p %t
5-
// RUN: echo 'export module x; int a, b;' > %t/x.cppm
6-
// RUN: echo 'export module x.y; int c;' > %t/x.y.cppm
4+
// RUN: mkdir %t
5+
// RUN: split-file %s %t
76
//
8-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
9-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
7+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/x.cppm -o %t/x.pcm
8+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fmodule-file=%t/x.pcm %t/x.y.cppm -o %t/x.y.pcm
109
//
1110
// Module implementation for unknown and known module. (The former is ill-formed.)
12-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
11+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify -x c++ %t/M.cpp \
1312
// RUN: -DTEST=1 -DEXPORT= -DMODULE_NAME=z
14-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
13+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify -x c++ %t/M.cpp \
1514
// RUN: -DTEST=2 -DEXPORT= -DMODULE_NAME=x
1615
//
1716
// Module interface for unknown and known module. (The latter is ill-formed due to
1817
// redefinition.)
19-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
18+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
2019
// RUN: -DTEST=3 -DEXPORT=export -DMODULE_NAME=z
21-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
20+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
2221
// RUN: -DTEST=4 -DEXPORT=export -DMODULE_NAME=x
2322
//
2423
// Miscellaneous syntax.
25-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
24+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
2625
// RUN: -DTEST=7 -DEXPORT=export -DMODULE_NAME='z elderberry'
27-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
26+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
2827
// RUN: -DTEST=8 -DEXPORT=export -DMODULE_NAME='z [[]]'
29-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
28+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
3029
// RUN: -DTEST=9 -DEXPORT=export -DMODULE_NAME='z [[fancy]]'
31-
// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=%t/x.y.pcm -verify %s \
30+
// RUN: %clang_cc1 -std=c++20 -I%t -fmodule-file=%t/x.y.pcm -verify %t/M.cpp \
3231
// RUN: -DTEST=10 -DEXPORT=export -DMODULE_NAME='z [[maybe_unused]]'
3332

33+
//--- x.cppm
34+
export module x;
35+
int a, b;
36+
37+
//--- x.y.cppm
38+
export module x.y;
39+
int c;
40+
41+
//--- M.cpp
42+
3443
EXPORT module MODULE_NAME;
3544
#if TEST == 4
3645
// expected-error@-2 {{redefinition of module 'x'}}
37-
// expected-note-re@module-declaration.cpp:* {{loaded from '{{.*[/\\]}}x.pcm'}}
46+
// expected-note-re@* {{loaded from '{{.*[/\\]}}x.pcm'}}
3847
#elif TEST == 7
3948
// expected-error@-5 {{expected ';'}} expected-error@-5 {{a type specifier is required}}
4049
#elif TEST == 9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
5+
// RUN: %clang_cc1 -std=c++20 %t/M.cppm -verify
6+
// RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-module-interface -o %t/M.pcm
7+
// RUN: %clang_cc1 -std=c++20 -fmodule-file=%t/M.pcm %t/M.cpp -verify
8+
//
9+
// RUN: %clang_cc1 -std=c++20 -fmodule-file=%t/M.pcm %t/user.cpp -verify
10+
11+
//--- M.cppm
12+
// expected-no-diagnostics
13+
export module M;
14+
15+
export int external_linkage_var;
16+
int module_linkage_var;
17+
static int internal_linkage_var;
18+
19+
export void external_linkage_fn() {}
20+
void module_linkage_fn() {}
21+
static void internal_linkage_fn() {}
22+
23+
export struct external_linkage_class {};
24+
struct module_linkage_class {};
25+
namespace {
26+
struct internal_linkage_class {};
27+
} // namespace
28+
29+
void use() {
30+
external_linkage_fn();
31+
module_linkage_fn();
32+
internal_linkage_fn();
33+
(void)external_linkage_class{};
34+
(void)module_linkage_class{};
35+
(void)internal_linkage_class{};
36+
(void)external_linkage_var;
37+
(void)module_linkage_var;
38+
(void)internal_linkage_var;
39+
}
40+
41+
//--- M.cpp
42+
// expected-no-diagnostics
43+
module M;
44+
45+
// FIXME: Use of internal linkage entities should be rejected.
46+
void use_from_module_impl() {
47+
external_linkage_fn();
48+
module_linkage_fn();
49+
internal_linkage_fn();
50+
(void)external_linkage_class{};
51+
(void)module_linkage_class{};
52+
(void)internal_linkage_class{};
53+
(void)external_linkage_var;
54+
(void)module_linkage_var;
55+
(void)internal_linkage_var;
56+
}
57+
58+
//--- user.cpp
59+
import M;
60+
61+
void use_from_module_impl() {
62+
external_linkage_fn();
63+
module_linkage_fn(); // expected-error {{declaration of 'module_linkage_fn' must be imported}}
64+
internal_linkage_fn(); // expected-error {{declaration of 'internal_linkage_fn' must be imported}}
65+
(void)external_linkage_class{};
66+
(void)module_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}}
67+
(void)internal_linkage_class{}; // expected-error {{undeclared identifier}} expected-error 0+{{}}
68+
// [email protected]:9 {{declaration here is not visible}}
69+
// [email protected]:10 {{declaration here is not visible}}
70+
(void)external_linkage_var;
71+
(void)module_linkage_var; // expected-error {{undeclared identifier}}
72+
(void)internal_linkage_var; // expected-error {{undeclared identifier}}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux %s -emit-module-interface -o %t
2+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -x pcm %t -emit-llvm -o - | FileCheck %s
3+
4+
export module M;
5+
6+
// CHECK-NOT: @_ZW1M1a ={{.*}}
7+
const int a = 1;
8+
// CHECK: @_ZW1M1b ={{.*}} constant i32 2
9+
export const int b = 2;
10+
11+
export int f() { return a + b; }

0 commit comments

Comments
 (0)