blob: 183709373d12aa0b695cbc9101db2439fcd7dfd6 [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;
34};
35const int &compat_use_before_redecl = compat::b;
36const int compat::a;
37const int compat::b;
38const int compat::c;
39const int compat::d;
40const int &compat_use_after_redecl1 = compat::c;
41const int &compat_use_after_redecl2 = compat::d;
42// CHECK: @_ZN6compat1bE = weak_odr constant i32 2
43// CHECK: @_ZN6compat1aE = weak_odr constant i32 1
44// CHECK: @_ZN6compat1cE = weak_odr constant i32 3
45// CHECK: @_ZN6compat1dE = linkonce_odr constant i32 4
46
Richard Smith62f19e72016-06-25 00:15:56 +000047template<typename T> struct X {
48 static int a;
49 static inline int b;
50 static int c;
51};
52// CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 10
53// CHECK: @_ZN1XIiE1bE = global i32 20
54// CHECK-NOT: @_ZN1XIiE1cE
55template<> inline int X<int>::a = 10;
56int &use3 = X<int>::a;
57template<> int X<int>::b = 20;
58template<> inline int X<int>::c = 30;
59
60// CHECK-LABEL: define {{.*}}global_var_init
61// CHECK: call i32 @_Z1fv
62
63// CHECK-LABEL: define {{.*}}global_var_init
64// CHECK-NOT: comdat
65// CHECK-SAME: {{$}}
66// CHECK: load atomic {{.*}} acquire
67// CHECK: br
68// CHECK: __cxa_guard_acquire(i64* @_ZGV1b)
69// CHECK: br
70// CHECK: call i32 @_Z1fv
71// CHECK: __cxa_guard_release(i64* @_ZGV1b)
72
73// CHECK-LABEL: define {{.*}}global_var_init
74// CHECK: call i32 @_Z1fv
75
76template<typename T> inline int d = f();
77int e = d<int>;
78
79// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat
80// CHECK: _ZGV1dIiE
81// CHECK-NOT: __cxa_guard_acquire(i64* @_ZGV1b)
82// CHECK: call i32 @_Z1fv
83// CHECK-NOT: __cxa_guard_release(i64* @_ZGV1b)