1 // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s 2 // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s 3 // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s 4 5 __vector char vv_c; 6 __vector signed char vv_sc; 7 __vector unsigned char vv_uc; 8 __vector short vv_s; 9 __vector signed short vv_ss; 10 __vector unsigned short vv_us; 11 __vector short int vv_si; 12 __vector signed short int vv_ssi; 13 __vector unsigned short int vv_usi; 14 __vector int vv_i; 15 __vector signed int vv_sint; 16 __vector unsigned int vv_ui; 17 __vector float vv_f; 18 __vector bool char vv_bc; 19 __vector bool short vv_bs; 20 __vector bool int vv_bi; 21 __vector __bool char vv___bc; 22 __vector __bool short vv___bs; 23 __vector __bool int vv___bi; 24 __vector __pixel vv_p; 25 __vector pixel vv__p; 26 __vector int vf__r(); 27 void vf__a(__vector int a); 28 void vf__a2(int b, __vector int a); 29 30 vector char v_c; 31 vector signed char v_sc; 32 vector unsigned char v_uc; 33 vector short v_s; 34 vector signed short v_ss; 35 vector unsigned short v_us; 36 vector short int v_si; 37 vector signed short int v_ssi; 38 vector unsigned short int v_usi; 39 vector int v_i; 40 vector signed int v_sint; 41 vector unsigned int v_ui; 42 vector float v_f; 43 vector bool char v_bc; 44 vector bool short v_bs; 45 vector bool int v_bi; 46 vector __bool char v___bc; 47 vector __bool short v___bs; 48 vector __bool int v___bi; 49 vector __pixel v_p; 50 vector pixel v__p; 51 vector int f__r(); 52 void f_a(vector int a); 53 void f_a2(int b, vector int a); 54 55 vector int v = (vector int)(-1); 56 57 // These should have warnings. 58 __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 59 __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 60 __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 61 __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 62 __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 63 __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 64 vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 65 vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 66 vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 67 vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 68 vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 69 vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 70 __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}} 71 vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}} 72 73 // These should have errors. 74 __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}} 75 vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}} 76 __vector bool long long v_bll1; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}} 77 __vector __bool long long v_bll2; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}} 78 vector bool long long v_bll3; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}} 79 vector __bool long long v_bll4; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}} 80 __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}} 81 vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}} 82 vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}} 83 vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} 84 vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} 85 vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} 86 vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} 87 vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} 88 vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} 89 vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}} 90 vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}} 91 vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} 92 vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} 93 vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} 94 vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}} 95 96 // vector long is deprecated, but vector long long is not. 97 vector long long v_ll; 98 vector signed long long v_sll; 99 vector unsigned long long v_ull; 100 101 void f() { 102 __vector unsigned int v = {0,0,0,0}; 103 __vector int v__cast = (__vector int)v; 104 __vector int v_cast = (vector int)v; 105 __vector char vb_cast = (vector char)v; 106 107 // Check some casting between gcc and altivec vectors. 108 #define gccvector __attribute__((vector_size(16))) 109 gccvector unsigned int gccv = {0,0,0,0}; 110 gccvector unsigned int gccv1 = gccv; 111 gccvector int gccv2 = (gccvector int)gccv; 112 gccvector unsigned int gccv3 = v; 113 __vector unsigned int av = gccv; 114 __vector int avi = (__vector int)gccv; 115 gccvector unsigned int gv = v; 116 gccvector int gvi = (gccvector int)v; 117 __attribute__((vector_size(8))) unsigned int gv8; 118 gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int' (vector of 4 'unsigned int' values)}} 119 av = gv8; // expected-error {{assigning to '__vector unsigned int' (vector of 4 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}} 120 121 v = gccv; 122 __vector unsigned int tv = gccv; 123 gccv = v; 124 gccvector unsigned int tgv = v; 125 } 126 127 // Now for the C++ version: 128 129 class vc__v { 130 __vector int v; 131 __vector int f__r(); 132 void f__a(__vector int a); 133 void f__a2(int b, __vector int a); 134 }; 135 136 class c_v { 137 vector int v; 138 vector int f__r(); 139 void f__a(vector int a); 140 void f__a2(int b, vector int a); 141 }; 142 143 144 // bug 6895 - Vectorl literal casting confusion. 145 vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); 146 vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); 147 vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); 148 vector int v4 = (vector int)(1, 2, 3, 4); 149 vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); 150 vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); 151 152 // bug 7553 - Problem with '==' and vectors 153 void func() { 154 bool res_b; 155 res_b = (vv_sc == vv_sc); 156 res_b = (vv_uc != vv_uc); 157 res_b = (vv_s > vv_s); 158 res_b = (vv_us >= vv_us); 159 res_b = (vv_i < vv_i); 160 res_b = (vv_ui <= vv_ui); 161 res_b = (vv_f <= vv_f); 162 } 163 164 // vecreturn attribute test 165 struct Vector 166 { 167 __vector float xyzw; 168 } __attribute__((vecreturn)); 169 170 Vector Add(Vector lhs, Vector rhs) 171 { 172 Vector result; 173 result.xyzw = vec_add(lhs.xyzw, rhs.xyzw); 174 return result; // This will (eventually) be returned in a register 175 } 176 177 // vecreturn attribute test - should error because of virtual function. 178 class VectorClassNonPod 179 { 180 __vector float xyzw; 181 public: 182 VectorClassNonPod() {} 183 virtual ~VectorClassNonPod() {} 184 } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)}} 185 186 // vecreturn attribute test - should error because of virtual function. 187 class VectorClassMultipleMembers 188 { 189 public: 190 __vector float xyzw; 191 __vector float abcd; 192 } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}} 193 194 template<typename... Args> void PR16874() { 195 (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}} 196 } 197 198