1*0aab3441SSimon Moll // RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++17
2*0aab3441SSimon Moll // Note that this test depends on the size of long-long to be different from
3*0aab3441SSimon Moll // int, so it specifies a triple.
4*0aab3441SSimon Moll 
5*0aab3441SSimon Moll using FourShorts = short __attribute__((__vector_size__(8)));
6*0aab3441SSimon Moll using TwoInts = int __attribute__((__vector_size__(8)));
7*0aab3441SSimon Moll using EightInts = int __attribute__((__vector_size__(32)));
8*0aab3441SSimon Moll using TwoUInts = unsigned __attribute__((__vector_size__(8)));
9*0aab3441SSimon Moll using FourInts = int __attribute__((__vector_size__(16)));
10*0aab3441SSimon Moll using FourUInts = unsigned __attribute__((__vector_size__(16)));
11*0aab3441SSimon Moll using TwoLongLong = long long __attribute__((__vector_size__(16)));
12*0aab3441SSimon Moll using FourLongLong = long long __attribute__((__vector_size__(32)));
13*0aab3441SSimon Moll using TwoFloats = float __attribute__((__vector_size__(8)));
14*0aab3441SSimon Moll using FourFloats = float __attribute__((__vector_size__(16)));
15*0aab3441SSimon Moll using TwoDoubles = double __attribute__((__vector_size__(16)));
16*0aab3441SSimon Moll using FourDoubles = double __attribute__((__vector_size__(32)));
17*0aab3441SSimon Moll using EightBools = bool __attribute__((ext_vector_type(8)));
18*0aab3441SSimon Moll 
19*0aab3441SSimon Moll EightInts eight_ints;
20*0aab3441SSimon Moll EightBools eight_bools;
21*0aab3441SSimon Moll EightBools other_eight_bools;
22*0aab3441SSimon Moll bool one_bool;
23*0aab3441SSimon Moll 
24*0aab3441SSimon Moll // Check the rules of the LHS/RHS of the conditional operator.
Operations()25*0aab3441SSimon Moll void Operations() {
26*0aab3441SSimon Moll   // Legal binary
27*0aab3441SSimon Moll   // (void)(eight_bools | other_eight_bools);
28*0aab3441SSimon Moll   // (void)(eight_bools & other_eight_bools);
29*0aab3441SSimon Moll   // (void)(eight_bools ^ other_eight_bools);
30*0aab3441SSimon Moll   // (void)(~eight_bools);
31*0aab3441SSimon Moll   // (void)(!eight_bools);
32*0aab3441SSimon Moll 
33*0aab3441SSimon Moll   // // Legal comparison
34*0aab3441SSimon Moll   // (void)(eight_bools == other_eight_bools);
35*0aab3441SSimon Moll   // (void)(eight_bools != other_eight_bools);
36*0aab3441SSimon Moll   // (void)(eight_bools < other_eight_bools);
37*0aab3441SSimon Moll   // (void)(eight_bools <= other_eight_bools);
38*0aab3441SSimon Moll   // (void)(eight_bools > other_eight_bools);
39*0aab3441SSimon Moll   // (void)(eight_bools >= other_eight_bools);
40*0aab3441SSimon Moll 
41*0aab3441SSimon Moll   // // Legal assignments
42*0aab3441SSimon Moll   // (void)(eight_bools |= other_eight_bools);
43*0aab3441SSimon Moll   // (void)(eight_bools &= other_eight_bools);
44*0aab3441SSimon Moll   // (void)(eight_bools ^= other_eight_bools);
45*0aab3441SSimon Moll 
46*0aab3441SSimon Moll   // Illegal operators
47*0aab3441SSimon Moll   (void)(eight_bools || other_eight_bools); // expected-error@47 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
48*0aab3441SSimon Moll   (void)(eight_bools && other_eight_bools); // expected-error@48 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
49*0aab3441SSimon Moll   (void)(eight_bools + other_eight_bools);  // expected-error@49 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
50*0aab3441SSimon Moll   (void)(eight_bools - other_eight_bools);  // expected-error@50 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
51*0aab3441SSimon Moll   (void)(eight_bools * other_eight_bools);  // expected-error@51 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
52*0aab3441SSimon Moll   (void)(eight_bools << other_eight_bools); // expected-error@52 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
53*0aab3441SSimon Moll   (void)(eight_bools >> other_eight_bools); // expected-error@53 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
54*0aab3441SSimon Moll   (void)(eight_bools / other_eight_bools);  // expected-error@54 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
55*0aab3441SSimon Moll   (void)(eight_bools % other_eight_bools);  // expected-error@55 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
56*0aab3441SSimon Moll 
57*0aab3441SSimon Moll   // Illegal assignment
58*0aab3441SSimon Moll   (void)(eight_bools += other_eight_bools);  // expected-error@58 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
59*0aab3441SSimon Moll   (void)(eight_bools -= other_eight_bools);  // expected-error@59 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
60*0aab3441SSimon Moll   (void)(eight_bools *= other_eight_bools);  // expected-error@60 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
61*0aab3441SSimon Moll   (void)(eight_bools <<= other_eight_bools); // expected-error@61 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
62*0aab3441SSimon Moll   (void)(eight_bools >>= other_eight_bools); // expected-error@62 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
63*0aab3441SSimon Moll   (void)(eight_bools /= other_eight_bools);  // expected-error@63 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
64*0aab3441SSimon Moll   (void)(eight_bools %= other_eight_bools);  // expected-error@64 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
65*0aab3441SSimon Moll 
66*0aab3441SSimon Moll   // Illegal in/decrements
67*0aab3441SSimon Moll   (void)(eight_bools++); // expected-error@67 {{cannot increment value of type 'EightBools' (vector of 8 'bool' values)}}
68*0aab3441SSimon Moll   (void)(++eight_bools); // expected-error@68 {{cannot increment value of type 'EightBools' (vector of 8 'bool' values)}}
69*0aab3441SSimon Moll   (void)(eight_bools--); // expected-error@69 {{cannot decrement value of type 'EightBools' (vector of 8 'bool' values)}}
70*0aab3441SSimon Moll   (void)(--eight_bools); // expected-error@70 {{cannot decrement value of type 'EightBools' (vector of 8 'bool' values)}}
71*0aab3441SSimon Moll 
72*0aab3441SSimon Moll   // No implicit promotion
73*0aab3441SSimon Moll   (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*0aab3441SSimon Moll   (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*0aab3441SSimon Moll }
76*0aab3441SSimon Moll 
77*0aab3441SSimon Moll // Allow scalar-to-vector broadcast. Do not allow bool vector conversions.
Conversions()78*0aab3441SSimon Moll void Conversions() {
79*0aab3441SSimon Moll   (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*0aab3441SSimon Moll   (void)((EightBools) one_bool); // Scalar-to-vector broadcast.
81*0aab3441SSimon Moll   (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*0aab3441SSimon Moll }
83*0aab3441SSimon Moll 
84*0aab3441SSimon Moll void foo(const bool& X);
85*0aab3441SSimon Moll 
86*0aab3441SSimon Moll // Disallow element-wise access.
ElementRefs()87*0aab3441SSimon Moll bool* ElementRefs() {
88*0aab3441SSimon Moll   eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}}
89*0aab3441SSimon Moll   &eight_bools.z;        // expected-error@89 {{illegal vector component name ''z''}}
90*0aab3441SSimon Moll   foo(eight_bools.w);    // expected-error@90 {{illegal vector component name ''w''}}
91*0aab3441SSimon Moll   foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name ''wyx''}}
92*0aab3441SSimon Moll }
93