1 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple i386-pc-linux-gnu %s 2 3 // This is separate from constexpr-builtin-bit-cast.cpp because we want to 4 // compile for i386 so that sizeof(long double) is 12. 5 6 typedef long double fp80x2_v __attribute__((ext_vector_type(2))); 7 8 static_assert(sizeof(long double) == 12, ""); 9 static_assert(sizeof(fp80x2_v) == 32, ""); 10 11 struct fp80x2_s { 12 char _data[2 * 10]; 13 unsigned char _pad[sizeof(fp80x2_v) - 2 * 10]; 14 operator ==fp80x2_s15 constexpr bool operator==(const fp80x2_s& rhs) const { 16 for (int i = 0; i < 2 * 10; ++i) 17 if (_data[i] != rhs._data[i]) 18 return false; 19 return true; 20 } 21 }; 22 23 namespace builtin_bit_cast { 24 constexpr static fp80x2_v test_vec_fp80 = { 1, 2 }; 25 constexpr static fp80x2_s test_str_fp80 = { { 0, 0, 0, 0, 0, 0, 0, -128, -1, 63, 0, 0, 0, 0, 0, 0, 0, -128, 0, 64 }, {} }; 26 27 // expected-error@+2 {{static assertion expression is not an integral constant expression}} 28 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 29 static_assert(__builtin_bit_cast(fp80x2_s, test_vec_fp80) == test_str_fp80, ""); 30 31 // expected-error@+2 {{static assertion expression is not an integral constant expression}} 32 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 33 static_assert(__builtin_bit_cast(fp80x2_s, __builtin_bit_cast(fp80x2_v, test_str_fp80)) == test_str_fp80, ""); 34 35 // expected-error@+2 {{constexpr variable 'bad_str_fp80_0' must be initialized by a constant expression}} 36 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 37 constexpr static char bad_str_fp80_0 = __builtin_bit_cast(fp80x2_s, test_vec_fp80)._pad[0]; 38 39 // expected-error@+2 {{constexpr variable 'bad_str_fp80_1' must be initialized by a constant expression}} 40 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 41 constexpr static char bad_str_fp80_1 = __builtin_bit_cast(fp80x2_s, test_vec_fp80)._pad[1]; 42 43 // expected-error@+2 {{constexpr variable 'bad_str_fp80_11' must be initialized by a constant expression}} 44 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 45 constexpr static char bad_str_fp80_11 = __builtin_bit_cast(fp80x2_s, test_vec_fp80)._pad[11]; 46 47 // expected-error@+2 {{constexpr variable 'struct2v' must be initialized by a constant expression}} 48 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 49 constexpr static fp80x2_v struct2v = __builtin_bit_cast(fp80x2_v, test_str_fp80); 50 } 51 52 namespace c_cast { 53 typedef short v12i16 __attribute((vector_size(24))); 54 typedef long double v2f80 __attribute((vector_size(24))); 55 56 // FIXME: re-enable the corresponding test cases in CodeGen/const-init.c when 57 // constexpr bitcast with x86_fp80 is supported 58 59 // expected-error@+2 {{constexpr variable 'b' must be initialized by a constant expression}} 60 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 61 constexpr static v12i16 b = (v12i16)(v2f80){1,2}; 62 63 // expected-error@+2 {{constexpr variable 'c' must be initialized by a constant expression}} 64 // expected-note@+1 {{constexpr bit cast involving type 'long double' is not yet supported}} 65 constexpr static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0}; 66 } 67