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