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