3 // RUN: split-file %s %t
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
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=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp --implicit-check-not=unused --implicit-check-not=global_module
10 // RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple -fmodule-file=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp --implicit-check-not=unused --implicit-check-not=global_module
13 // CHECK-DAG: @extern_var_global_module = external {{(dso_local )?}}global
14 // CHECK-DAG: @inline_var_global_module = linkonce_odr {{(dso_local )?}}global
15 // CHECK-DAG: @_ZL24static_var_global_module = internal global
16 // CHECK-DAG: @_ZL23const_var_global_module = internal constant
18 // With strong-ownership, the module is mangled into exported symbols
19 // that are attached to a named module.
20 // CHECK-DAG: @_ZW6Module19extern_var_exported = external {{(dso_local )?}}global
21 // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we
22 // can discard this global and its initializer (if any), and other TUs are not
23 // permitted to run the initializer for this variable.
24 // CHECK-DAG: @_ZW6Module19inline_var_exported = linkonce_odr {{(dso_local )?}}global
25 // CHECK-DAG: @_ZW6Module18const_var_exported = {{(dso_local )?}}constant
27 // CHECK-DAG: @_ZW6Module25extern_var_module_linkage = external {{(dso_local )?}}global
28 // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we
29 // can discard this global and its initializer (if any), and other TUs are not
30 // permitted to run the initializer for this variable.
31 // CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
32 // CHECK-DAG: @_ZL25static_var_module_linkage = internal
33 // CHECK-DAG: @_ZW6Module24const_var_module_linkage = {{(dso_local )?}}constant
35 // CHECK-DAG: @_ZW6Module25unused_var_module_linkage = {{(dso_local )?}}global i32 4
39 static void unused_static_global_module() {}
40 static void used_static_global_module() {}
42 inline void unused_inline_global_module() {}
43 inline void used_inline_global_module() {}
45 extern int extern_var_global_module;
46 inline int inline_var_global_module;
47 static int static_var_global_module;
48 const int const_var_global_module = 3;
50 // CHECK: define {{(dso_local )?}}void {{.*}}@_Z23noninline_global_modulev
51 void noninline_global_module() {
52 // FIXME: This should be promoted to module linkage and given a
53 // module-mangled name, if it's called from an inline function within
54 // the module interface.
55 // (We should try to avoid this when it's not reachable from outside
56 // the module interface unit.)
57 // CHECK: define internal {{.*}}@_ZL25used_static_global_modulev
58 used_static_global_module();
59 // CHECK: define linkonce_odr {{.*}}@_Z25used_inline_global_modulev
60 used_inline_global_module();
62 (void)&extern_var_global_module;
63 (void)&inline_var_global_module;
64 (void)&static_var_global_module;
65 (void)&const_var_global_module;
71 inline void unused_inline_exported() {}
72 inline void used_inline_exported() {}
74 extern int extern_var_exported;
75 inline int inline_var_exported;
76 const int const_var_exported = 3;
78 // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6Module18noninline_exportedv
79 void noninline_exported() {
80 (void)&extern_var_exported;
81 (void)&inline_var_exported;
82 (void)&const_var_exported;
86 static void unused_static_module_linkage() {}
88 static void used_static_module_linkage() {}
90 inline void unused_inline_module_linkage() {}
91 inline void used_inline_module_linkage() {}
93 extern int extern_var_module_linkage;
94 inline int inline_var_module_linkage;
95 static int static_var_module_linkage;
96 const int const_var_module_linkage = 3;
98 // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6Module24noninline_module_linkagev
99 // CHECK: define {{.*}}void {{.*}}@_ZL26used_static_module_linkagev
100 void noninline_module_linkage() {
101 used_static_module_linkage();
102 // CHECK: define linkonce_odr {{.*}}@_ZW6Module26used_inline_module_linkagev
103 used_inline_module_linkage();
105 (void)&extern_var_module_linkage;
106 (void)&inline_var_module_linkage;
107 (void)&static_var_module_linkage;
108 (void)&const_var_module_linkage;
111 int unused_var_module_linkage = 4;
112 static int unused_static_var_module_linkage = 5;
113 inline int unused_inline_var_module_linkage = 6;
114 const int unused_const_var_module_linkage = 7;
120 // CHECK: define {{(dso_local )?}}void @_ZW6Module1fNS_1a1bENS0_1cE(
121 void f(a::b, a::c) {}
125 // CHECK-DAG: @_ZW6Module19extern_var_exported = external {{(dso_local )?}}global
126 // CHECK-DAG: @_ZW6Module19inline_var_exported = linkonce_odr {{(dso_local )?}}global
127 // CHECK-DAG: @_ZW6Module18const_var_exported = available_externally {{(dso_local )?}}constant i32 3,
129 // CHECK-DAG: @_ZW6Module25extern_var_module_linkage = external {{(dso_local )?}}global
130 // CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
131 // CHECK-DAG: @_ZL25static_var_module_linkage = internal {{(dso_local )?}}global i32 0,
132 // CHECK-DAG: @_ZW6Module24const_var_module_linkage = available_externally {{(dso_local )?}}constant i32 3,
137 // CHECK: define linkonce_odr {{.*}}@_ZW6Module20used_inline_exportedv
138 used_inline_exported();
139 // CHECK: declare {{.*}}@_ZW6Module18noninline_exportedv
140 noninline_exported();
142 (void)&extern_var_exported;
143 (void)&inline_var_exported;
144 (void)&const_var_exported;
146 // CHECK: define linkonce_odr {{.*}}@_ZW6Module26used_inline_module_linkagev
147 used_inline_module_linkage();
149 // CHECK: declare {{.*}}@_ZW6Module24noninline_module_linkagev
150 noninline_module_linkage();
152 (void)&extern_var_module_linkage;
153 (void)&inline_var_module_linkage;
155 // FIXME: Issue #61427 Internal-linkage declarations in the interface TU
156 // should not be not visible here.
157 (void)&static_var_module_linkage; // FIXME: Should not be visible here.
159 (void)&const_var_module_linkage; // FIXME: will be visible after P2788R0
164 // CHECK-DAG: @_ZW6Module19extern_var_exported = external {{(dso_local )?}}global
165 // CHECK-DAG: @_ZW6Module19inline_var_exported = linkonce_odr {{(dso_local )?}}global
166 // CHECK-DAG: @_ZW6Module18const_var_exported = available_externally {{(dso_local )?}}constant i32 3
171 // CHECK: define linkonce_odr {{.*}}@_ZW6Module20used_inline_exportedv
172 used_inline_exported();
173 // CHECK: declare {{.*}}@_ZW6Module18noninline_exportedv
174 noninline_exported();
176 (void)&extern_var_exported;
177 (void)&inline_var_exported;
178 (void)&const_var_exported;
180 // Internal-linkage declarations are not visible here.
181 // Module-linkage declarations are not visible here.