blob: 848ec1f106f68cf44c13e1cf5e893868616f010e [file] [log] [blame]
Eric Christophere84f9eb2010-08-26 00:42:16 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fno-lax-vector-conversions %s
Nate Begeman58d29a42009-06-26 00:50:28 +00002
3typedef __attribute__(( ext_vector_type(2) )) float float2;
4typedef __attribute__(( ext_vector_type(4) )) int int4;
Nate Begeman1bd1f6e2009-06-28 02:36:38 +00005typedef __attribute__(( ext_vector_type(8) )) short short8;
Nate Begeman58d29a42009-06-26 00:50:28 +00006typedef __attribute__(( ext_vector_type(4) )) float float4;
7typedef float t3 __attribute__ ((vector_size (16)));
8
9static void test() {
10 float2 vec2;
11 float4 vec4, vec4_2;
12 int4 ivec4;
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000013 short8 ish8;
Nate Begeman58d29a42009-06-26 00:50:28 +000014 t3 vec4_3;
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000015 int *ptr;
16 int i;
Nate Begeman58d29a42009-06-26 00:50:28 +000017
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000018 vec4 = 5.0f;
Nate Begeman58d29a42009-06-26 00:50:28 +000019 vec4 = (float4)5.0f;
20 vec4 = (float4)5;
21 vec4 = (float4)vec4_3;
22
23 ivec4 = (int4)5.0f;
24 ivec4 = (int4)5;
25 ivec4 = (int4)vec4_3;
26
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000027 i = (int)ivec4; // expected-error {{invalid conversion between vector type 'int4' and integer type 'int' of different size}}
Douglas Gregord4eea832010-04-09 00:35:39 +000028 i = ivec4; // expected-error {{assigning to 'int' from incompatible type 'int4'}}
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000029
30 ivec4 = (int4)ptr; // expected-error {{invalid conversion between vector type 'int4' and scalar type 'int *'}}
31
Nate Begeman58d29a42009-06-26 00:50:28 +000032 vec4 = (float4)vec2; // expected-error {{invalid conversion between ext-vector type 'float4' and 'float2'}}
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000033
34 ish8 += 5; // expected-error {{can't convert between vector values of different size ('short8' and 'int')}}
35 ish8 += (short)5;
36 ivec4 *= 5;
37 vec4 /= 5.2f;
38 vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' and 'int')}}
39 ivec4 %= 4;
Eli Friedmanb9b4b782011-06-23 18:10:35 +000040 ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('int4' and 'float4')}}
Nate Begeman1bd1f6e2009-06-28 02:36:38 +000041 ivec4 += (int4)vec4;
42 ivec4 -= ivec4;
43 ivec4 |= ivec4;
44 ivec4 += ptr; // expected-error {{can't convert between vector values of different size ('int4' and 'int *')}}
Nate Begeman58d29a42009-06-26 00:50:28 +000045}
Douglas Gregor0c293ea2010-06-22 23:07:26 +000046
Douglas Gregor27cac992010-06-30 17:30:41 +000047typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2'}}
Douglas Gregor4b131722010-06-22 23:13:52 +000048
49void inc(float2 f2) {
50 f2++; // expected-error{{cannot increment value of type 'float2'}}
Douglas Gregor00619622010-06-22 23:41:02 +000051 __real f2; // expected-error{{invalid type 'float2' to __real operator}}
Douglas Gregor4b131722010-06-22 23:13:52 +000052}