Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s |
Bill Schmidt | 1cf7c64 | 2014-06-13 18:30:06 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify %s |
| 3 | // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify %s |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 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; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 18 | __vector bool char vv_bc; |
| 19 | __vector bool short vv_bs; |
| 20 | __vector bool int vv_bi; |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 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; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 40 | vector bool char v_bc; |
| 41 | vector bool short v_bs; |
| 42 | vector bool int v_bi; |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 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 | |
Chris Lattner | b596ac7 | 2010-04-20 05:19:10 +0000 | [diff] [blame] | 49 | vector int v = (vector int)(-1); |
| 50 | |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 51 | // These should have warnings. |
Chris Lattner | 0a65574 | 2010-03-07 18:50:21 +0000 | [diff] [blame] | 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}} |
Bill Schmidt | 691e01d | 2014-10-31 19:19:24 +0000 | [diff] [blame^] | 64 | __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}} |
| 65 | vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}} |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 66 | vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}} |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 67 | |
| 68 | // These should have errors. |
Bill Schmidt | 691e01d | 2014-10-31 19:19:24 +0000 | [diff] [blame^] | 69 | __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}} |
| 70 | vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}} |
| 71 | __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}} |
| 72 | vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}} |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 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'}} |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 80 | |
Hal Finkel | 3a1f4c7 | 2014-08-24 04:50:19 +0000 | [diff] [blame] | 81 | // vector long is deprecated, but vector long long is not. |
| 82 | vector long long v_ll; |
| 83 | vector signed long long v_sll; |
| 84 | vector unsigned long long v_ull; |
| 85 | |
Richard Smith | 3092a3b | 2012-05-09 18:56:43 +0000 | [diff] [blame] | 86 | typedef char i8; |
| 87 | typedef short i16; |
| 88 | typedef int i32; |
| 89 | struct S { |
| 90 | // i8, i16, i32 here are field names, not type names. |
| 91 | vector bool i8; // expected-error {{requires a specifier or qualifier}} |
| 92 | vector pixel i16; |
| 93 | vector long i32; // expected-warning {{deprecated}} |
| 94 | }; |
| 95 | |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 96 | void f() { |
| 97 | __vector unsigned int v = {0,0,0,0}; |
| 98 | __vector int v__cast = (__vector int)v; |
| 99 | __vector int v_cast = (vector int)v; |
| 100 | __vector char vb_cast = (vector char)v; |
| 101 | |
| 102 | // Check some casting between gcc and altivec vectors. |
| 103 | #define gccvector __attribute__((vector_size(16))) |
| 104 | gccvector unsigned int gccv = {0,0,0,0}; |
| 105 | gccvector unsigned int gccv1 = gccv; |
| 106 | gccvector int gccv2 = (gccvector int)gccv; |
| 107 | gccvector unsigned int gccv3 = v; |
| 108 | __vector unsigned int av = gccv; |
| 109 | __vector int avi = (__vector int)gccv; |
| 110 | gccvector unsigned int gv = v; |
| 111 | gccvector int gvi = (gccvector int)v; |
| 112 | __attribute__((vector_size(8))) unsigned int gv8; |
Benjamin Kramer | 1adc8c3 | 2014-04-25 20:41:38 +0000 | [diff] [blame] | 113 | 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)}} |
| 114 | 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] | 115 | |
| 116 | v = gccv; |
| 117 | __vector unsigned int tv = gccv; |
| 118 | gccv = v; |
| 119 | gccvector unsigned int tgv = v; |
Anton Yartsev | 3f8f288 | 2010-11-18 03:19:30 +0000 | [diff] [blame] | 120 | |
| 121 | int res_i; |
| 122 | // bug 7553 - Problem with '==' and vectors |
| 123 | res_i = (vv_sc == vv_sc); |
| 124 | res_i = (vv_uc != vv_uc); |
| 125 | res_i = (vv_s > vv_s); |
| 126 | res_i = (vv_us >= vv_us); |
| 127 | res_i = (vv_i < vv_i); |
| 128 | res_i = (vv_ui <= vv_ui); |
| 129 | res_i = (vv_f <= vv_f); |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 130 | } |
John Thompson | 781ad17 | 2010-06-30 22:55:51 +0000 | [diff] [blame] | 131 | |
| 132 | // bug 6895 - Vectorl literal casting confusion. |
Chandler Carruth | bc0f9ae | 2011-04-25 07:09:43 +0000 | [diff] [blame] | 133 | vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); |
| 134 | vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); |
| 135 | vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); |
| 136 | vector int v4 = (vector int)(1, 2, 3, 4); |
John Thompson | 781ad17 | 2010-06-30 22:55:51 +0000 | [diff] [blame] | 137 | vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); |
| 138 | vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); |