176 lines · cpp
1// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s2 3namespace std {4 using size_t = decltype(sizeof(0));5 template<typename> struct tuple_size;6 template<size_t, typename> struct tuple_element;7}8 9struct Y { int n; };10struct X { X(); X(Y); X(const X&); ~X(); };11 12struct A { int a : 13; bool b; };13 14struct B {};15template<> struct std::tuple_size<B> { enum { value = 2 }; };16template<> struct std::tuple_element<0,B> { using type = X; };17template<> struct std::tuple_element<1,B> { using type = const int&; };18template<int N> auto get(B) {19 if constexpr (N == 0)20 return Y();21 else22 return 0.0;23}24 25using C = int[2];26 27typedef int D __attribute__((ext_vector_type(2)));28 29using E = _Complex int;30 31template<typename T> T &make();32 33// CHECK: @_ZDC2a12a2E ={{.*}} global {{.*}} zeroinitializer, align 434auto [a1, a2] = make<A>();35// CHECK: @_ZDC2b12b2E ={{.*}} global {{.*}} zeroinitializer, align 136// CHECK: @b1 ={{.*}} global ptr null, align 837// CHECK: @_ZGR2b1_ = internal global {{.*}} zeroinitializer, align 138// CHECK: @b2 ={{.*}} global ptr null, align 839// CHECK: @_ZGR2b2_ = internal global i32 0, align 440auto [b1, b2] = make<B>();41// CHECK: @_ZDC2c12c2E ={{.*}} global ptr null, align 842auto &[c1, c2] = make<C>();43// CHECK: @_ZDC2d12d2E ={{.*}} global <2 x i32> zeroinitializer, align 844auto [d1, d2] = make<D>();45// CHECK: @_ZDC2e12e2E ={{.*}} global { i32, i32 } zeroinitializer, align 446auto [e1, e2] = make<E>();47 48// CHECK: call {{.*}}ptr @_Z4makeI1AERT_v()49// CHECK: call {{.*}}memcpy{{.*}}@_ZDC2a12a2E50 51// CHECK: @_Z4makeI1BERT_v()52// CHECK: call i32 @_Z3getILi0EEDa1B()53// CHECK: call void @_ZN1XC1E1Y(ptr {{[^,]*}} @_ZGR2b1_, i3254// CHECK: call i32 @__cxa_atexit({{.*}}@_ZN1XD1Ev{{.*}}@_ZGR2b1_55// CHECK: store ptr @_ZGR2b1_,56//57// CHECK: call noundef double @_Z3getILi1EEDa1B()58// CHECK: fptosi double %{{.*}} to i3259// CHECK: store i32 %{{.*}}, ptr @_ZGR2b2_60// CHECK: store ptr @_ZGR2b2_, ptr @b261 62// CHECK: call {{.*}}ptr @_Z4makeIA2_iERT_v()63// CHECK: store {{.*}}, ptr @_ZDC2c12c2E64 65// CHECK: call {{.*}}ptr @_Z4makeIDv2_iERT_v()66// CHECK: store {{.*}}, ptr @_ZDC2d12d2E, align 867 68// CHECK: call {{.*}}ptr @_Z4makeICiERT_v()69// CHECK: store i32 %{{.*}}, ptr @_ZDC2e12e2E70// CHECK: store i32 %{{.*}}, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_ZDC2e12e2E, i32 0, i32 1)71 72// CHECK: define{{.*}} i32 @_Z12test_globalsv()73int test_globals() {74 return a2 + b2 + c2 + d2 + e2;75 // CHECK: load i8, ptr getelementptr inbounds nuw (%struct.A, ptr @_ZDC2a12a2E, i32 0, i32 1)76 //77 // CHECK: %[[b2:.*]] = load ptr, ptr @b278 // CHECK: load i32, ptr %[[b2]]79 //80 // CHECK: %[[c1c2:.*]] = load ptr, ptr @_ZDC2c12c2E81 // CHECK: %[[c2:.*]] = getelementptr inbounds [2 x i32], ptr %[[c1c2]], i64 0, i64 182 // CHECK: load i32, ptr %[[c2]]83 //84 // CHECK: %[[d1d2:.*]] = load <2 x i32>, ptr @_ZDC2d12d2E85 // CHECK: extractelement <2 x i32> %[[d1d2]], i32 186 //87 // CHECK: load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @_ZDC2e12e2E, i32 0, i32 1)88}89 90// CHECK: define{{.*}} i32 @_Z11test_localsv()91int test_locals() {92 auto [b1, b2] = make<B>();93 94 // CHECK: @_Z4makeI1BERT_v()95 // CHECK: call i32 @_Z3getILi0EEDa1B()96 // CHECK: call void @_ZN1XC1E1Y(ptr {{[^,]*}} %[[b1:.*]], i3297 //98 // CHECK: call noundef double @_Z3getILi1EEDa1B()99 // CHECK: %[[cvt:.*]] = fptosi double %{{.*}} to i32100 // CHECK: store i32 %[[cvt]], ptr %[[b2:.*]],101 // CHECK: store ptr %[[b2]], ptr %[[b2ref:.*]],102 103 return b2;104 // CHECK: %[[b2:.*]] = load ptr, ptr %[[b2ref]]105 // CHECK: load i32, ptr %[[b2]]106 107 // CHECK: call {{.*}}@_ZN1XD1Ev({{.*}}%[[b1]])108}109 110// CHECK: define{{.*}} void @_Z13test_bitfieldR1A(111void test_bitfield(A &a) {112 auto &[a1, a2] = a;113 a1 = 5;114 // CHECK: load i16, ptr %[[BITFIELD:.*]],115 // CHECK: and i16 %{{.*}}, -8192116 // CHECK: or i16 %{{.*}}, 5117 // CHECK: store i16 %{{.*}}, ptr %[[BITFIELD]],118}119 120// CHECK-LABEL: define {{.*}}@_Z18test_static_simple121void test_static_simple() {122 static auto [x1, x2] = make<A>();123 // CHECK: load atomic i8, {{.*}}@_ZGVZ18test_static_simplevEDC2x12x2E{{.*}} acquire, align 8124 // CHECK: br i1125 // CHECK: @__cxa_guard_acquire(126 // CHECK: call {{.*}} @_Z4makeI1AERT_v(127 // CHECK: memcpy{{.*}} @_ZZ18test_static_simplevEDC2x12x2E128 // CHECK: @__cxa_guard_release(129}130 131// CHECK-LABEL: define {{.*}}@_Z17test_static_tuple132int test_static_tuple() {133 // Note that the desugaring specified for this construct requires three134 // separate guarded initializations. It is possible for an exception to be135 // thrown after the first initialization and before the second, and if that136 // happens, we are not permitted to rerun the first initialization, so we137 // 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 i8, {{.*}}@_ZGVZ17test_static_tuplevEDC2x12x2E{{.*}} acquire, align 8142 // CHECK: br i1143 // 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 i8, {{.*}}@_ZGVZ17test_static_tuplevE2x1{{.*}} acquire, align 8149 // CHECK: br i1150 // 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_tuplevE2x1155 // CHECK: call void @__cxa_guard_release({{.*}} @_ZGVZ17test_static_tuplevE2x1)156 157 // Initialization of the secret 'x2' variable.158 // CHECK: load atomic i8, {{.*}}@_ZGVZ17test_static_tuplevE2x2{{.*}} acquire, align 8159 // CHECK: br i1160 // 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_tuplevE2x2164 // 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_tuplevE2x2170 // CHECK: load171 // CHECK: ret172 int f() { return x2; }173 };174 return Inner().f();175}176