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.
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)));
20 EightBools eight_bools
;
21 EightBools other_eight_bools
;
24 // Check the rules of the LHS/RHS of the conditional operator.
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);
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);
41 // // Legal assignments
42 // (void)(eight_bools |= other_eight_bools);
43 // (void)(eight_bools &= other_eight_bools);
44 // (void)(eight_bools ^= other_eight_bools);
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')}}
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')}}
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)}}
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))}}
77 // Allow scalar-to-vector broadcast. Do not allow bool vector 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}}
84 void foo(const bool& X
);
86 // Disallow element-wise access.
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''}}
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);