| 1 |
// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++17 |
| 2 |
// Note that this test depends on the size of long-long to be different from |
| 3 |
// int, so it specifies a triple. |
| 4 |
|
| 5 |
using FourShorts = short __attribute__((__vector_size__(8))); |
| 6 |
using TwoInts = int __attribute__((__vector_size__(8))); |
| 7 |
using EightInts = int __attribute__((__vector_size__(32))); |
| 8 |
using TwoUInts = unsigned __attribute__((__vector_size__(8))); |
| 9 |
using FourInts = int __attribute__((__vector_size__(16))); |
| 10 |
using FourUInts = unsigned __attribute__((__vector_size__(16))); |
| 11 |
using TwoLongLong = long long __attribute__((__vector_size__(16))); |
| 12 |
using FourLongLong = long long __attribute__((__vector_size__(32))); |
| 13 |
using TwoFloats = float __attribute__((__vector_size__(8))); |
| 14 |
using FourFloats = float __attribute__((__vector_size__(16))); |
| 15 |
using TwoDoubles = double __attribute__((__vector_size__(16))); |
| 16 |
using FourDoubles = double __attribute__((__vector_size__(32))); |
| 17 |
using EightBools = bool __attribute__((ext_vector_type(8))); |
| 18 |
|
| 19 |
EightInts eight_ints; |
| 20 |
EightBools eight_bools; |
| 21 |
EightBools other_eight_bools; |
| 22 |
bool one_bool; |
| 23 |
|
| 24 |
// Check the rules of the LHS/RHS of the conditional operator. |
| 25 |
void Operations() { |
| 26 |
// Legal binary |
| 27 |
// (void)(eight_bools | other_eight_bools); |
| 28 |
// (void)(eight_bools & other_eight_bools); |
| 29 |
// (void)(eight_bools ^ other_eight_bools); |
| 30 |
// (void)(~eight_bools); |
| 31 |
// (void)(!eight_bools); |
| 32 |
|
| 33 |
// // Legal comparison |
| 34 |
// (void)(eight_bools == other_eight_bools); |
| 35 |
// (void)(eight_bools != other_eight_bools); |
| 36 |
// (void)(eight_bools < other_eight_bools); |
| 37 |
// (void)(eight_bools <= other_eight_bools); |
| 38 |
// (void)(eight_bools > other_eight_bools); |
| 39 |
// (void)(eight_bools >= other_eight_bools); |
| 40 |
|
| 41 |
// // Legal assignments |
| 42 |
// (void)(eight_bools |= other_eight_bools); |
| 43 |
// (void)(eight_bools &= other_eight_bools); |
| 44 |
// (void)(eight_bools ^= other_eight_bools); |
| 45 |
|
| 46 |
// Illegal operators |
| 47 |
(void)(eight_bools || other_eight_bools); // expected-error@47 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 48 |
(void)(eight_bools && other_eight_bools); // expected-error@48 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 49 |
(void)(eight_bools + other_eight_bools); // expected-error@49 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 50 |
(void)(eight_bools - other_eight_bools); // expected-error@50 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 51 |
(void)(eight_bools * other_eight_bools); // expected-error@51 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 52 |
(void)(eight_bools << other_eight_bools); // expected-error@52 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 53 |
(void)(eight_bools >> other_eight_bools); // expected-error@53 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 54 |
(void)(eight_bools / other_eight_bools); // expected-error@54 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 55 |
(void)(eight_bools % other_eight_bools); // expected-error@55 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 56 |
|
| 57 |
// Illegal assignment |
| 58 |
(void)(eight_bools += other_eight_bools); // expected-error@58 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 59 |
(void)(eight_bools -= other_eight_bools); // expected-error@59 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 60 |
(void)(eight_bools *= other_eight_bools); // expected-error@60 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 61 |
(void)(eight_bools <<= other_eight_bools); // expected-error@61 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 62 |
(void)(eight_bools >>= other_eight_bools); // expected-error@62 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 63 |
(void)(eight_bools /= other_eight_bools); // expected-error@63 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 64 |
(void)(eight_bools %= other_eight_bools); // expected-error@64 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}} |
| 65 |
|
| 66 |
// Illegal in/decrements |
| 67 |
(void)(eight_bools++); // expected-error@67 {{cannot increment value of type 'EightBools' (vector of 8 'bool' values)}} |
| 68 |
(void)(++eight_bools); // expected-error@68 {{cannot increment value of type 'EightBools' (vector of 8 'bool' values)}} |
| 69 |
(void)(eight_bools--); // expected-error@69 {{cannot decrement value of type 'EightBools' (vector of 8 'bool' values)}} |
| 70 |
(void)(--eight_bools); // expected-error@70 {{cannot decrement value of type 'EightBools' (vector of 8 'bool' values)}} |
| 71 |
|
| 72 |
// No implicit promotion |
| 73 |
(void)(eight_bools + eight_ints); // expected-error@73 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightInts' (vector of 8 'int' values))}} |
| 74 |
(void)(eight_ints - eight_bools); // expected-error@74 {{invalid operands to binary expression ('EightInts' (vector of 8 'int' values) and 'EightBools' (vector of 8 'bool' values))}} |
| 75 |
} |
| 76 |
|
| 77 |
// Allow scalar-to-vector broadcast. Do not allow bool vector conversions. |
| 78 |
void Conversions() { |
| 79 |
(void)((long)eight_bools); // expected-error@79 {{C-style cast from vector 'EightBools' (vector of 8 'bool' values) to scalar 'long' of different size}} |
| 80 |
(void)((EightBools) one_bool); // Scalar-to-vector broadcast. |
| 81 |
(void)((char)eight_bools); // expected-error@81 {{C-style cast from vector 'EightBools' (vector of 8 'bool' values) to scalar 'char' of different size}} |
| 82 |
} |
| 83 |
|
| 84 |
void foo(const bool& X); |
| 85 |
|
| 86 |
// Disallow element-wise access. |
| 87 |
bool* ElementRefs() { |
| 88 |
eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} |
| 89 |
&eight_bools.z; // expected-error@89 {{illegal vector component name 'z'}} |
| 90 |
foo(eight_bools.w); // expected-error@90 {{illegal vector component name 'w'}} |
| 91 |
foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} |
| 92 |
} |
| 93 |
|
| 94 |
void Sizeof() { |
| 95 |
using FourBools = bool __attribute__((ext_vector_type(4))); |
| 96 |
using NineBools = bool __attribute__((ext_vector_type(9))); |
| 97 |
using TwentyEightBools = bool __attribute__((ext_vector_type(28))); |
| 98 |
using ThirtyThreeBools = bool __attribute__((ext_vector_type(33))); |
| 99 |
using SixtyFiveBools = bool __attribute__((ext_vector_type(65))); |
| 100 |
using Bool129 = bool __attribute__((ext_vector_type(129))); |
| 101 |
using Bool150 = bool __attribute__((ext_vector_type(150))); |
| 102 |
using Bool195 = bool __attribute__((ext_vector_type(195))); |
| 103 |
using Bool257 = bool __attribute__((ext_vector_type(257))); |
| 104 |
static_assert(sizeof(FourBools) == 1); |
| 105 |
static_assert(sizeof(EightBools) == 1); |
| 106 |
static_assert(sizeof(NineBools) == 2); |
| 107 |
static_assert(sizeof(TwentyEightBools) == 4); |
| 108 |
static_assert(sizeof(ThirtyThreeBools) == 8); |
| 109 |
static_assert(sizeof(SixtyFiveBools) == 16); |
| 110 |
static_assert(sizeof(Bool129) == 32); |
| 111 |
static_assert(sizeof(Bool150) == 32); |
| 112 |
static_assert(sizeof(Bool195) == 32); |
| 113 |
static_assert(sizeof(Bool257) == 64); |
| 114 |
} |
| 115 |
|
| 116 |
#if !__has_feature(ext_vector_type_boolean) |
| 117 |
#error "FAIL" |
| 118 |
#endif |