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