• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
2 
3 namespace std {
4   using size_t = decltype(sizeof(0));
5   template<typename> struct tuple_size;
6   template<size_t, typename> struct tuple_element;
7 }
8 
9 struct Y { int n; };
10 struct X { X(); X(Y); X(const X&); ~X(); };
11 
12 struct A { int a : 13; bool b; };
13 
14 struct 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&; };
get(B)18 template<int N> auto get(B) {
19   if constexpr (N == 0)
20     return Y();
21   else
22     return 0.0;
23 }
24 
25 using C = int[2];
26 
27 typedef int D __attribute__((ext_vector_type(2)));
28 
29 using E = _Complex int;
30 
31 template<typename T> T &make();
32 
33 // CHECK: @_ZDC2a12a2E = global {{.*}} zeroinitializer, align 4
34 auto [a1, a2] = make<A>();
35 // CHECK: @_ZDC2b12b2E = global {{.*}} zeroinitializer, align 1
36 // CHECK: @b1 = global {{.*}}* null, align 8
37 // CHECK: @_ZGR2b1_ = internal global {{.*}} zeroinitializer, align 1
38 // CHECK: @b2 = global i32* null, align 8
39 // CHECK: @_ZGR2b2_ = internal global i32 0, align 4
40 auto [b1, b2] = make<B>();
41 // CHECK: @_ZDC2c12c2E = global [2 x i32]* 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>();
47 
48 // CHECK: call {{.*}}* @_Z4makeI1AERT_v()
49 // CHECK: call {{.*}}memcpy{{.*}}@_ZDC2a12a2E
50 
51 // CHECK: @_Z4makeI1BERT_v()
52 //   CHECK: call i32 @_Z3getILi0EEDa1B()
53 //   CHECK: call void @_ZN1XC1E1Y({{.*}}* {{[^,]*}} @_ZGR2b1_, i32
54 //   CHECK: call i32 @__cxa_atexit({{.*}}@_ZN1XD1Ev{{.*}}@_ZGR2b1_
55 //   CHECK: store {{.*}}* @_ZGR2b1_,
56 //
57 //   CHECK: call double @_Z3getILi1EEDa1B()
58 //   CHECK: fptosi double %{{.*}} to i32
59 //   CHECK: store i32 %{{.*}}, i32* @_ZGR2b2_
60 //   CHECK: store i32* @_ZGR2b2_, i32** @b2
61 
62 // CHECK: call {{.*}}* @_Z4makeIA2_iERT_v()
63 // CHECK: store {{.*}}, [2 x i32]** @_ZDC2c12c2E
64 
65 // CHECK: call {{.*}}* @_Z4makeIDv2_iERT_v()
66 // CHECK: store {{.*}}, <2 x i32>* @_ZDC2d12d2E, align 8
67 
68 // CHECK: call {{.*}}* @_Z4makeICiERT_v()
69 // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({ i32, i32 }, { i32, i32 }* @_ZDC2e12e2E, i32 0, i32 0)
70 // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({ i32, i32 }, { i32, i32 }* @_ZDC2e12e2E, i32 0, i32 1)
71 
72 // CHECK: define i32 @_Z12test_globalsv()
test_globals()73 int test_globals() {
74   return a2 + b2 + c2 + d2 + e2;
75   // CHECK: load i8, i8* getelementptr inbounds (%struct.A, %struct.A* @_ZDC2a12a2E, i32 0, i32 1)
76   //
77   // CHECK: %[[b2:.*]] = load i32*, i32** @b2
78   // CHECK: load i32, i32* %[[b2]]
79   //
80   // CHECK: %[[c1c2:.*]] = load [2 x i32]*, [2 x i32]** @_ZDC2c12c2E
81   // CHECK: %[[c2:.*]] = getelementptr inbounds [2 x i32], [2 x i32]* %[[c1c2]], i64 0, i64 1
82   // CHECK: load i32, i32* %[[c2]]
83   //
84   // CHECK: %[[d1d2:.*]] = load <2 x i32>, <2 x i32>* @_ZDC2d12d2E
85   // CHECK: extractelement <2 x i32> %[[d1d2]], i32 1
86   //
87   // CHECK: load i32, i32* getelementptr inbounds ({ i32, i32 }, { i32, i32 }* @_ZDC2e12e2E, i32 0, i32 1)
88 }
89 
90 // CHECK: define i32 @_Z11test_localsv()
test_locals()91 int test_locals() {
92   auto [b1, b2] = make<B>();
93 
94   // CHECK: @_Z4makeI1BERT_v()
95   //   CHECK: call i32 @_Z3getILi0EEDa1B()
96   //   CHECK: call void @_ZN1XC1E1Y({{.*}}* {{[^,]*}} %[[b1:.*]], i32
97   //
98   //   CHECK: call double @_Z3getILi1EEDa1B()
99   //   CHECK: %[[cvt:.*]] = fptosi double %{{.*}} to i32
100   //   CHECK: store i32 %[[cvt]], i32* %[[b2:.*]],
101   //   CHECK: store i32* %[[b2]], i32** %[[b2ref:.*]],
102 
103   return b2;
104   // CHECK: %[[b2:.*]] = load i32*, i32** %[[b2ref]]
105   // CHECK: load i32, i32* %[[b2]]
106 
107   // CHECK: call {{.*}}@_ZN1XD1Ev({{.*}}%[[b1]])
108 }
109 
110 // CHECK: define void @_Z13test_bitfieldR1A(
test_bitfield(A & a)111 void test_bitfield(A &a) {
112   auto &[a1, a2] = a;
113   a1 = 5;
114   // CHECK: load i16, i16* %[[BITFIELD:.*]],
115   // CHECK: and i16 %{{.*}}, -8192
116   // CHECK: or i16 %{{.*}}, 5
117   // CHECK: store i16 %{{.*}}, i16* %[[BITFIELD]],
118 }
119 
120 // CHECK-LABEL: define {{.*}}@_Z18test_static_simple
test_static_simple()121 void test_static_simple() {
122   static auto [x1, x2] = make<A>();
123   // CHECK: load atomic {{.*}}i64* @_ZGVZ18test_static_simplevEDC2x12x2E
124   // CHECK: br i1
125   // CHECK: @__cxa_guard_acquire(
126   // CHECK: call {{.*}} @_Z4makeI1AERT_v(
127   // CHECK: memcpy{{.*}} @_ZZ18test_static_simplevEDC2x12x2E
128   // CHECK: @__cxa_guard_release(
129 }
130 
131 // CHECK-LABEL: define {{.*}}@_Z17test_static_tuple
test_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>();
139 
140   // Initialization of the implied variable.
141   // CHECK: load atomic {{.*}} @_ZGVZ17test_static_tuplevEDC2x12x2E
142   // CHECK: br i1
143   // CHECK: @__cxa_guard_acquire({{.*}} @_ZGVZ17test_static_tuplevEDC2x12x2E)
144   // CHECK: call {{.*}} @_Z4makeI1BERT_v(
145   // CHECK: @__cxa_guard_release({{.*}} @_ZGVZ17test_static_tuplevEDC2x12x2E)
146 
147   // Initialization of the secret 'x1' variable.
148   // CHECK: load atomic {{.*}} @_ZGVZ17test_static_tuplevE2x1
149   // CHECK: br i1
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)
156 
157   // Initialization of the secret 'x2' variable.
158   // CHECK: load atomic {{.*}} @_ZGVZ17test_static_tuplevE2x2
159   // CHECK: br i1
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)
165 
166   struct Inner {
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
170     // CHECK: load
171     // CHECK: ret
172     int f() { return x2; }
173   };
174   return Inner().f();
175 }
176