blob: 2d16acd8a8c23b167a6893734555d3961a1b2315 [file] [log] [blame]
Richard Smith62f19e72016-06-25 00:15:56 +00001// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s
2
3struct Q {
4 // CHECK: @_ZN1Q1kE = linkonce_odr constant i32 5, comdat
5 static constexpr int k = 5;
6};
7const int &r = Q::k;
8
9int f();
10
11// const does not imply internal linkage.
12// CHECK: @external_inline = linkonce_odr constant i32 5, comdat
13inline const int external_inline = 5;
14const int &use1 = external_inline;
15
16// static still does, though.
17// CHECK: @_ZL15internal_inline = internal constant i32 5
18static inline const int internal_inline = 5;
19const int &use2 = internal_inline;
20
21int a = f();
22// CHECK: @b = linkonce_odr global i32 0, comdat
23// CHECK: @_ZGV1b = linkonce_odr global i64 0, comdat($b)
24inline int b = f();
25int c = f();
26
Richard Smithd9b90092016-07-02 01:32:16 +000027// For compatibility with C++11 and C++14, an out-of-line declaration of a
28// static constexpr local variable promotes the variable to weak_odr.
29struct compat {
30 static constexpr int a = 1;
31 static constexpr int b = 2;
32 static constexpr int c = 3;
33 static inline constexpr int d = 4;
Richard Smith8910fe62017-10-23 03:58:34 +000034 static const int e = 5;
35 static const int f = 6;
36 static const int g = 7;
Richard Smithd9b90092016-07-02 01:32:16 +000037};
38const int &compat_use_before_redecl = compat::b;
39const int compat::a;
40const int compat::b;
41const int compat::c;
42const int compat::d;
Richard Smith8910fe62017-10-23 03:58:34 +000043const int compat::e;
44constexpr int compat::f;
45constexpr inline int compat::g;
Richard Smithd9b90092016-07-02 01:32:16 +000046const int &compat_use_after_redecl1 = compat::c;
47const int &compat_use_after_redecl2 = compat::d;
Richard Smith8910fe62017-10-23 03:58:34 +000048const int &compat_use_after_redecl3 = compat::g;
49// CHECK-DAG: @_ZN6compat1bE = weak_odr constant i32 2
50// CHECK-DAG: @_ZN6compat1aE = weak_odr constant i32 1
51// CHECK-DAG: @_ZN6compat1cE = weak_odr constant i32 3
52// CHECK-DAG: @_ZN6compat1dE = linkonce_odr constant i32 4
53// CHECK-DAG: @_ZN6compat1eE = constant i32 5
54// CHECK-DAG: @_ZN6compat1fE = weak_odr constant i32 6
55// CHECK-DAG: @_ZN6compat1gE = linkonce_odr constant i32 7
Richard Smithd9b90092016-07-02 01:32:16 +000056
Richard Smith62f19e72016-06-25 00:15:56 +000057template<typename T> struct X {
58 static int a;
59 static inline int b;
60 static int c;
61};
62// CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 10
63// CHECK: @_ZN1XIiE1bE = global i32 20
64// CHECK-NOT: @_ZN1XIiE1cE
65template<> inline int X<int>::a = 10;
66int &use3 = X<int>::a;
67template<> int X<int>::b = 20;
68template<> inline int X<int>::c = 30;
69
Richard Smithe1246122017-11-03 01:26:01 +000070template<typename T> struct Y;
71template<> struct Y<int> {
72 static constexpr int a = 123;
73 static constexpr int b = 456;
74 static constexpr int c = 789;
75};
76// CHECK: @_ZN1YIiE1aE = weak_odr constant i32 123
77constexpr int Y<int>::a;
78// CHECK: @_ZN1YIiE1bE = linkonce_odr constant i32 456
79const int &yib = Y<int>::b;
80// CHECK-NOT: @_ZN1YIiE1cE
81
Richard Smith62f19e72016-06-25 00:15:56 +000082// CHECK-LABEL: define {{.*}}global_var_init
83// CHECK: call i32 @_Z1fv
84
85// CHECK-LABEL: define {{.*}}global_var_init
86// CHECK-NOT: comdat
87// CHECK-SAME: {{$}}
88// CHECK: load atomic {{.*}} acquire
89// CHECK: br
90// CHECK: __cxa_guard_acquire(i64* @_ZGV1b)
91// CHECK: br
92// CHECK: call i32 @_Z1fv
93// CHECK: __cxa_guard_release(i64* @_ZGV1b)
94
95// CHECK-LABEL: define {{.*}}global_var_init
96// CHECK: call i32 @_Z1fv
97
98template<typename T> inline int d = f();
99int e = d<int>;
100
101// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat
102// CHECK: _ZGV1dIiE
103// CHECK-NOT: __cxa_guard_acquire(i64* @_ZGV1b)
104// CHECK: call i32 @_Z1fv
105// CHECK-NOT: __cxa_guard_release(i64* @_ZGV1b)