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