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 __pixel vv_p; 22 __vector pixel vv__p; 23 __vector int vf__r(); 24 void vf__a(__vector int a); 25 void vf__a2(int b, __vector int a); 26 27 vector char v_c; 28 vector signed char v_sc; 29 vector unsigned char v_uc; 30 vector short v_s; 31 vector signed short v_ss; 32 vector unsigned short v_us; 33 vector short int v_si; 34 vector signed short int v_ssi; 35 vector unsigned short int v_usi; 36 vector int v_i; 37 vector signed int v_sint; 38 vector unsigned int v_ui; 39 vector float v_f; 40 vector bool char v_bc; 41 vector bool short v_bs; 42 vector bool int v_bi; 43 vector __pixel v_p; 44 vector pixel v__p; 45 vector int f__r(); 46 void f_a(vector int a); 47 void f_a2(int b, vector int a); 48 49 vector int v = (vector int)(-1); 50 51 // These should have warnings. 52 __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 53 __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 54 __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 55 __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 56 __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 57 __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 58 vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 59 vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 60 vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 61 vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 62 vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 63 vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}} 64 __vector long double vv_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} 65 vector long double v_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} 66 67 // These should have errors. 68 __vector double vv_d1; // expected-error {{cannot use 'double' with '__vector'}} 69 vector double v_d2; // expected-error {{cannot use 'double' with '__vector'}} 70 __vector long double vv_ld3; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} 71 vector long double v_ld4; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} 72 vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}} 73 vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} 74 vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} 75 vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} 76 vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}} 77 vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}} 78 vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} 79 vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}} 80 81 void f() { 82 __vector unsigned int v = {0,0,0,0}; 83 __vector int v__cast = (__vector int)v; 84 __vector int v_cast = (vector int)v; 85 __vector char vb_cast = (vector char)v; 86 87 // Check some casting between gcc and altivec vectors. 88 #define gccvector __attribute__((vector_size(16))) 89 gccvector unsigned int gccv = {0,0,0,0}; 90 gccvector unsigned int gccv1 = gccv; 91 gccvector int gccv2 = (gccvector int)gccv; 92 gccvector unsigned int gccv3 = v; 93 __vector unsigned int av = gccv; 94 __vector int avi = (__vector int)gccv; 95 gccvector unsigned int gv = v; 96 gccvector int gvi = (gccvector int)v; 97 __attribute__((vector_size(8))) unsigned int gv8; 98 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)}} 99 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)}} 100 101 v = gccv; 102 __vector unsigned int tv = gccv; 103 gccv = v; 104 gccvector unsigned int tgv = v; 105 } 106 107 // Now for the C++ version: 108 109 class vc__v { 110 __vector int v; 111 __vector int f__r(); 112 void f__a(__vector int a); 113 void f__a2(int b, __vector int a); 114 }; 115 116 class c_v { 117 vector int v; 118 vector int f__r(); 119 void f__a(vector int a); 120 void f__a2(int b, vector int a); 121 }; 122 123 124 // bug 6895 - Vectorl literal casting confusion. 125 vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); 126 vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); 127 vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); 128 vector int v4 = (vector int)(1, 2, 3, 4); 129 vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); 130 vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); 131 132 // bug 7553 - Problem with '==' and vectors 133 void func() { 134 bool res_b; 135 res_b = (vv_sc == vv_sc); 136 res_b = (vv_uc != vv_uc); 137 res_b = (vv_s > vv_s); 138 res_b = (vv_us >= vv_us); 139 res_b = (vv_i < vv_i); 140 res_b = (vv_ui <= vv_ui); 141 res_b = (vv_f <= vv_f); 142 } 143 144 // vecreturn attribute test 145 struct Vector 146 { 147 __vector float xyzw; 148 } __attribute__((vecreturn)); 149 150 Vector Add(Vector lhs, Vector rhs) 151 { 152 Vector result; 153 result.xyzw = vec_add(lhs.xyzw, rhs.xyzw); 154 return result; // This will (eventually) be returned in a register 155 } 156 157 // vecreturn attribute test - should error because of virtual function. 158 class VectorClassNonPod 159 { 160 __vector float xyzw; 161 public: 162 VectorClassNonPod() {} 163 virtual ~VectorClassNonPod() {} 164 } __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)}} 165 166 // vecreturn attribute test - should error because of virtual function. 167 class VectorClassMultipleMembers 168 { 169 public: 170 __vector float xyzw; 171 __vector float abcd; 172 } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}} 173 174 template<typename... Args> void PR16874() { 175 (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}} 176 } 177