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#include <altivec.h>
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;
19__vector bool char vv_bc;
20__vector bool short vv_bs;
21__vector bool int vv_bi;
22__vector __bool char vv___bc;
23__vector __bool short vv___bs;
24__vector __bool int vv___bi;
25__vector __pixel vv_p;
26__vector pixel vv__p;
27__vector int vf__r();
28void vf__a(__vector int a);
29void vf__a2(int b, __vector int a);
30
31vector char v_c;
32vector signed char v_sc;
33vector unsigned char v_uc;
34vector short v_s;
35vector signed  short v_ss;
36vector unsigned  short v_us;
37vector short int v_si;
38vector signed short int v_ssi;
39vector unsigned short int v_usi;
40vector int v_i;
41vector signed int v_sint;
42vector unsigned int v_ui;
43vector float v_f;
44vector bool char v_bc;
45vector bool short v_bs;
46vector bool int v_bi;
47vector __bool char v___bc;
48vector __bool short v___bs;
49vector __bool int v___bi;
50vector __pixel v_p;
51vector pixel v__p;
52vector int f__r();
53void f_a(vector int a);
54void f_a2(int b, vector int a);
55
56vector int v = (vector int)(-1);
57
58// These should have warnings.
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}}
65vector long v_l;                    // expected-warning {{Use of 'long' with '__vector' is deprecated}}
66vector signed long v_sl;            // expected-warning {{Use of 'long' with '__vector' is deprecated}}
67vector unsigned long v_ul;          // expected-warning {{Use of 'long' with '__vector' is deprecated}}
68vector long int v_li;               // expected-warning {{Use of 'long' with '__vector' is deprecated}}
69vector signed long int v_sli;       // expected-warning {{Use of 'long' with '__vector' is deprecated}}
70vector unsigned long int v_uli;     // expected-warning {{Use of 'long' with '__vector' is deprecated}}
71__vector long double  vv_ld;        // expected-error {{cannot use 'long double' with '__vector'}}
72vector long double  v_ld;           // expected-error {{cannot use 'long double' with '__vector'}}
73
74// These should have errors.
75__vector double vv_d1;               // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
76vector 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}}
79vector 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}}
80vector __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}}
81__vector long double  vv_ld3;        // expected-error {{cannot use 'long double' with '__vector'}}
82vector long double  v_ld4;           // expected-error {{cannot use 'long double' with '__vector'}}
83vector bool v_b;                     // expected-error {{C++ requires a type specifier for all declarations}}
84vector bool float v_bf;              // expected-error {{cannot use 'float' with '__vector bool'}}
85vector bool double v_bd;             // expected-error {{cannot use 'double' with '__vector bool'}}
86vector bool pixel v_bp;              // expected-error {{cannot use '__pixel' with '__vector bool'}}
87vector bool signed char v_bsc;       // expected-error {{cannot use 'signed' with '__vector bool'}}
88vector bool unsigned int v_bsc2;     // expected-error {{cannot use 'unsigned' with '__vector bool'}}
89vector bool long v_bl;               // expected-error {{cannot use 'long' with '__vector bool'}}
90vector __bool float v___bf;          // expected-error {{cannot use 'float' with '__vector bool'}}
91vector __bool double v___bd;         // expected-error {{cannot use 'double' with '__vector bool'}}
92vector __bool pixel v___bp;          // expected-error {{cannot use '__pixel' with '__vector bool'}}
93vector __bool signed char v___bsc;   // expected-error {{cannot use 'signed' with '__vector bool'}}
94vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
95vector __bool long v___bl;           // expected-error {{cannot use 'long' with '__vector bool'}}
96
97// vector long is deprecated, but vector long long is not.
98vector long long v_ll;
99vector signed long long v_sll;
100vector unsigned long long v_ull;
101
102void 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;
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)}}
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
130class 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
137class 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
144
145// bug 6895 - Vectorl literal casting confusion.
146vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
147vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
148vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
149vector int v4 = (vector int)(1, 2, 3, 4);
150vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
151vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
152
153// bug 7553 - Problem with '==' and vectors
154void func() {
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);
163}
164
165// vecreturn attribute test
166struct Vector
167{
168	__vector float xyzw;
169} __attribute__((vecreturn));
170
171Vector 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}
177
178// vecreturn attribute test - should error because of virtual function.
179class VectorClassNonPod
180{
181	__vector float xyzw;
182public:
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.
188class VectorClassMultipleMembers
189{
190public:
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}}
194
195template<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}
198
199