1 // RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
4 using size_t = decltype(sizeof(0));
5 template<typename
> struct tuple_size
;
6 template<size_t, typename
> struct tuple_element
;
10 struct X
{ X(); X(Y
); X(const X
&); ~X(); };
12 struct A
{ int a
: 13; bool b
; };
15 template<> struct std::tuple_size
<B
> { enum { value
= 2 }; };
16 template<> struct std::tuple_element
<0,B
> { using type
= X
; };
17 template<> struct std::tuple_element
<1,B
> { using type
= const int&; };
18 template<int N
> auto get(B
) {
27 typedef int D
__attribute__((ext_vector_type(2)));
29 using E
= _Complex
int;
31 template<typename T
> T
&make();
33 // CHECK: @_ZDC2a12a2E ={{.*}} global {{.*}} zeroinitializer, align 4
34 auto [a1
, a2
] = make
<A
>();
35 // CHECK: @_ZDC2b12b2E ={{.*}} global {{.*}} zeroinitializer, align 1
36 // CHECK: @b1 ={{.*}} global ptr null, align 8
37 // CHECK: @_ZGR2b1_ = internal global {{.*}} zeroinitializer, align 1
38 // CHECK: @b2 ={{.*}} global ptr null, align 8
39 // CHECK: @_ZGR2b2_ = internal global i32 0, align 4
40 auto [b1
, b2
] = make
<B
>();
41 // CHECK: @_ZDC2c12c2E ={{.*}} global ptr null, align 8
42 auto &[c1
, c2
] = make
<C
>();
43 // CHECK: @_ZDC2d12d2E ={{.*}} global <2 x i32> zeroinitializer, align 8
44 auto [d1
, d2
] = make
<D
>();
45 // CHECK: @_ZDC2e12e2E ={{.*}} global { i32, i32 } zeroinitializer, align 4
46 auto [e1
, e2
] = make
<E
>();
48 // CHECK: call {{.*}}ptr @_Z4makeI1AERT_v()
49 // CHECK: call {{.*}}memcpy{{.*}}@_ZDC2a12a2E
51 // CHECK: @_Z4makeI1BERT_v()
52 // CHECK: call i32 @_Z3getILi0EEDa1B()
53 // CHECK: call void @_ZN1XC1E1Y(ptr {{[^,]*}} @_ZGR2b1_, i32
54 // CHECK: call i32 @__cxa_atexit({{.*}}@_ZN1XD1Ev{{.*}}@_ZGR2b1_
55 // CHECK: store ptr @_ZGR2b1_,
57 // CHECK: call noundef double @_Z3getILi1EEDa1B()
58 // CHECK: fptosi double %{{.*}} to i32
59 // CHECK: store i32 %{{.*}}, ptr @_ZGR2b2_
60 // CHECK: store ptr @_ZGR2b2_, ptr @b2
62 // CHECK: call {{.*}}ptr @_Z4makeIA2_iERT_v()
63 // CHECK: store {{.*}}, ptr @_ZDC2c12c2E
65 // CHECK: call {{.*}}ptr @_Z4makeIDv2_iERT_v()
66 // CHECK: store {{.*}}, ptr @_ZDC2d12d2E, align 8
68 // CHECK: call {{.*}}ptr @_Z4makeICiERT_v()
69 // CHECK: store i32 %{{.*}}, ptr @_ZDC2e12e2E
70 // CHECK: store i32 %{{.*}}, ptr getelementptr inbounds ({ i32, i32 }, ptr @_ZDC2e12e2E, i32 0, i32 1)
72 // CHECK: define{{.*}} i32 @_Z12test_globalsv()
74 return a2
+ b2
+ c2
+ d2
+ e2
;
75 // CHECK: load i8, ptr getelementptr inbounds (%struct.A, ptr @_ZDC2a12a2E, i32 0, i32 1)
77 // CHECK: %[[b2:.*]] = load ptr, ptr @b2
78 // CHECK: load i32, ptr %[[b2]]
80 // CHECK: %[[c1c2:.*]] = load ptr, ptr @_ZDC2c12c2E
81 // CHECK: %[[c2:.*]] = getelementptr inbounds [2 x i32], ptr %[[c1c2]], i64 0, i64 1
82 // CHECK: load i32, ptr %[[c2]]
84 // CHECK: %[[d1d2:.*]] = load <2 x i32>, ptr @_ZDC2d12d2E
85 // CHECK: extractelement <2 x i32> %[[d1d2]], i32 1
87 // CHECK: load i32, ptr getelementptr inbounds ({ i32, i32 }, ptr @_ZDC2e12e2E, i32 0, i32 1)
90 // CHECK: define{{.*}} i32 @_Z11test_localsv()
92 auto [b1
, b2
] = make
<B
>();
94 // CHECK: @_Z4makeI1BERT_v()
95 // CHECK: call i32 @_Z3getILi0EEDa1B()
96 // CHECK: call void @_ZN1XC1E1Y(ptr {{[^,]*}} %[[b1:.*]], i32
98 // CHECK: call noundef double @_Z3getILi1EEDa1B()
99 // CHECK: %[[cvt:.*]] = fptosi double %{{.*}} to i32
100 // CHECK: store i32 %[[cvt]], ptr %[[b2:.*]],
101 // CHECK: store ptr %[[b2]], ptr %[[b2ref:.*]],
104 // CHECK: %[[b2:.*]] = load ptr, ptr %[[b2ref]]
105 // CHECK: load i32, ptr %[[b2]]
107 // CHECK: call {{.*}}@_ZN1XD1Ev({{.*}}%[[b1]])
110 // CHECK: define{{.*}} void @_Z13test_bitfieldR1A(
111 void test_bitfield(A
&a
) {
114 // CHECK: load i16, ptr %[[BITFIELD:.*]],
115 // CHECK: and i16 %{{.*}}, -8192
116 // CHECK: or i16 %{{.*}}, 5
117 // CHECK: store i16 %{{.*}}, ptr %[[BITFIELD]],
120 // CHECK-LABEL: define {{.*}}@_Z18test_static_simple
121 void test_static_simple() {
122 static auto [x1
, x2
] = make
<A
>();
123 // CHECK: load atomic i8, {{.*}}@_ZGVZ18test_static_simplevEDC2x12x2E{{.*}} acquire, align 8
125 // CHECK: @__cxa_guard_acquire(
126 // CHECK: call {{.*}} @_Z4makeI1AERT_v(
127 // CHECK: memcpy{{.*}} @_ZZ18test_static_simplevEDC2x12x2E
128 // CHECK: @__cxa_guard_release(
131 // CHECK-LABEL: define {{.*}}@_Z17test_static_tuple
132 int test_static_tuple() {
133 // Note that the desugaring specified for this construct requires three
134 // separate guarded initializations. It is possible for an exception to be
135 // thrown after the first initialization and before the second, and if that
136 // happens, we are not permitted to rerun the first initialization, so we
137 // can't combine these into a single guarded initialization in general.
138 static auto [x1
, x2
] = make
<B
>();
140 // Initialization of the implied variable.
141 // CHECK: load atomic i8, {{.*}}@_ZGVZ17test_static_tuplevEDC2x12x2E{{.*}} acquire, align 8
143 // CHECK: @__cxa_guard_acquire({{.*}} @_ZGVZ17test_static_tuplevEDC2x12x2E)
144 // CHECK: call {{.*}} @_Z4makeI1BERT_v(
145 // CHECK: @__cxa_guard_release({{.*}} @_ZGVZ17test_static_tuplevEDC2x12x2E)
147 // Initialization of the secret 'x1' variable.
148 // CHECK: load atomic i8, {{.*}}@_ZGVZ17test_static_tuplevE2x1{{.*}} acquire, align 8
150 // CHECK: @__cxa_guard_acquire({{.*}} @_ZGVZ17test_static_tuplevE2x1)
151 // CHECK: call {{.*}} @_Z3getILi0EEDa1B(
152 // CHECK: call {{.*}} @_ZN1XC1E1Y({{.*}} @_ZGRZ17test_static_tuplevE2x1_,
153 // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN1XD1Ev, {{.*}} @_ZGRZ17test_static_tuplevE2x1_
154 // CHECK: store {{.*}} @_ZGRZ17test_static_tuplevE2x1_, {{.*}} @_ZZ17test_static_tuplevE2x1
155 // CHECK: call void @__cxa_guard_release({{.*}} @_ZGVZ17test_static_tuplevE2x1)
157 // Initialization of the secret 'x2' variable.
158 // CHECK: load atomic i8, {{.*}}@_ZGVZ17test_static_tuplevE2x2{{.*}} acquire, align 8
160 // CHECK: @__cxa_guard_acquire({{.*}} @_ZGVZ17test_static_tuplevE2x2)
161 // CHECK: call {{.*}} @_Z3getILi1EEDa1B(
162 // CHECK: store {{.*}}, {{.*}} @_ZGRZ17test_static_tuplevE2x2_
163 // CHECK: store {{.*}} @_ZGRZ17test_static_tuplevE2x2_, {{.*}} @_ZZ17test_static_tuplevE2x2
164 // CHECK: call void @__cxa_guard_release({{.*}} @_ZGVZ17test_static_tuplevE2x2)
167 // CHECK-LABEL: define {{.*}}@_ZZ17test_static_tuplevEN5Inner1fEv(
168 // FIXME: This first load should be constant-folded to the _ZGV... temporary.
169 // CHECK: load {{.*}} @_ZZ17test_static_tuplevE2x2
172 int f() { return x2
; }