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 |
2 | |
3 | // CHECK-DAG: @extern_var_global_module = external {{(dso_local )?}}global |
4 | // CHECK-DAG: @inline_var_global_module = linkonce_odr {{(dso_local )?}}global |
5 | // CHECK-DAG: @_ZL24static_var_global_module = internal global |
6 | // CHECK-DAG: @_ZL23const_var_global_module = internal constant |
7 | // |
8 | // For ABI compatibility, these symbols do not include the module name. |
9 | // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global |
10 | // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we |
11 | // can discard this global and its initializer (if any), and other TUs are not |
12 | // permitted to run the initializer for this variable. |
13 | // CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global |
14 | // CHECK-DAG: @_ZW6ModuleE19static_var_exported = {{(dso_local )?}}global |
15 | // CHECK-DAG: @const_var_exported = {{(dso_local )?}}constant |
16 | // |
17 | // CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external {{(dso_local )?}}global |
18 | // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we |
19 | // can discard this global and its initializer (if any), and other TUs are not |
20 | // permitted to run the initializer for this variable. |
21 | // CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global |
22 | // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = {{(dso_local )?}}global |
23 | // CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = {{(dso_local )?}}constant |
24 | // |
25 | // CHECK-DAG: @_ZW6ModuleE25unused_var_module_linkage = {{(dso_local )?}}global i32 4 |
26 | // CHECK-DAG: @_ZW6ModuleE32unused_static_var_module_linkage = {{(dso_local )?}}global i32 5 |
27 | // CHECK-DAG: @_ZW6ModuleE31unused_const_var_module_linkage = {{(dso_local )?}}constant i32 7 |
28 | |
29 | static void unused_static_global_module() {} |
30 | static void used_static_global_module() {} |
31 | |
32 | inline void unused_inline_global_module() {} |
33 | inline void used_inline_global_module() {} |
34 | |
35 | extern int extern_var_global_module; |
36 | inline int inline_var_global_module; |
37 | static int static_var_global_module; |
38 | const int const_var_global_module = 3; |
39 | |
40 | // CHECK: define {{(dso_local )?}}void {{.*}}@_Z23noninline_global_modulev |
41 | void noninline_global_module() { |
42 | // FIXME: This should be promoted to module linkage and given a |
43 | // module-mangled name, if it's called from an inline function within |
44 | // the module interface. |
45 | // (We should try to avoid this when it's not reachable from outside |
46 | // the module interface unit.) |
47 | // CHECK: define internal {{.*}}@_ZL25used_static_global_modulev |
48 | used_static_global_module(); |
49 | // CHECK: define linkonce_odr {{.*}}@_Z25used_inline_global_modulev |
50 | used_inline_global_module(); |
51 | |
52 | (void)&extern_var_global_module; |
53 | (void)&inline_var_global_module; |
54 | (void)&static_var_global_module; |
55 | (void)&const_var_global_module; |
56 | } |
57 | |
58 | export module Module; |
59 | |
60 | export { |
61 | // FIXME: These should be ill-formed: you can't export an internal linkage |
62 | // symbol, per [dcl.module.interface]p2. |
63 | // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6ModuleE22unused_static_exportedv |
64 | static void unused_static_exported() {} |
65 | // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6ModuleE20used_static_exportedv |
66 | static void used_static_exported() {} |
67 | |
68 | inline void unused_inline_exported() {} |
69 | inline void used_inline_exported() {} |
70 | |
71 | extern int extern_var_exported; |
72 | inline int inline_var_exported; |
73 | // FIXME: This should be ill-formed: you can't export an internal linkage |
74 | // symbol. |
75 | static int static_var_exported; |
76 | const int const_var_exported = 3; |
77 | |
78 | // CHECK: define {{(dso_local )?}}void {{.*}}@_Z18noninline_exportedv |
79 | void noninline_exported() { |
80 | used_static_exported(); |
81 | // CHECK: define linkonce_odr {{.*}}@_Z20used_inline_exportedv |
82 | used_inline_exported(); |
83 | |
84 | (void)&extern_var_exported; |
85 | (void)&inline_var_exported; |
86 | (void)&static_var_exported; |
87 | (void)&const_var_exported; |
88 | } |
89 | } |
90 | |
91 | // FIXME: Ideally we wouldn't emit this as its name is not visible outside this |
92 | // TU, but this module interface might contain a template that can use this |
93 | // function so we conservatively emit it for now. |
94 | // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6ModuleE28unused_static_module_linkagev |
95 | static void unused_static_module_linkage() {} |
96 | // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6ModuleE26used_static_module_linkagev |
97 | static void used_static_module_linkage() {} |
98 | |
99 | inline void unused_inline_module_linkage() {} |
100 | inline void used_inline_module_linkage() {} |
101 | |
102 | extern int extern_var_module_linkage; |
103 | inline int inline_var_module_linkage; |
104 | static int static_var_module_linkage; |
105 | const int const_var_module_linkage = 3; |
106 | |
107 | // CHECK: define {{(dso_local )?}}void {{.*}}@_ZW6ModuleE24noninline_module_linkagev |
108 | void noninline_module_linkage() { |
109 | used_static_module_linkage(); |
110 | // CHECK: define linkonce_odr {{.*}}@_ZW6ModuleE26used_inline_module_linkagev |
111 | used_inline_module_linkage(); |
112 | |
113 | (void)&extern_var_module_linkage; |
114 | (void)&inline_var_module_linkage; |
115 | (void)&static_var_module_linkage; |
116 | (void)&const_var_module_linkage; |
117 | } |
118 | |
119 | int unused_var_module_linkage = 4; |
120 | static int unused_static_var_module_linkage = 5; |
121 | inline int unused_inline_var_module_linkage = 6; |
122 | const int unused_const_var_module_linkage = 7; |
123 | |
124 | struct a { |
125 | struct b {}; |
126 | struct c {}; |
127 | }; |
128 | // CHECK: define {{(dso_local )?}}void @_ZW6ModuleE1fW_0EN1a1bEW_0ENS_1cE( |
129 | void f(a::b, a::c) {} |
130 | |