[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang / test / Sema / ext_vector_casts.c
blob8bf2737e0bfab107f5a16920e1b9e3baa8e7d762
1 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -fsyntax-only -verify -flax-vector-conversions=none -Wconversion %s
3 typedef __attribute__((ext_vector_type(8))) _Bool BoolVector;
5 typedef __attribute__(( ext_vector_type(2) )) float float2;
6 typedef __attribute__(( ext_vector_type(3) )) float float3;
7 typedef __attribute__(( ext_vector_type(4) )) int int4;
8 typedef __attribute__(( ext_vector_type(8) )) short short8;
9 typedef __attribute__(( ext_vector_type(4) )) float float4;
10 typedef float t3 __attribute__ ((vector_size (16)));
11 typedef __typeof__(sizeof(int)) size_t;
12 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
13 typedef size_t stride4 __attribute__((ext_vector_type(4)));
14 typedef _Bool bool4 __attribute__(( ext_vector_type(4) ));
16 static void test(void) {
17 float2 vec2;
18 float3 vec3;
19 float4 vec4, vec4_2;
20 int4 ivec4;
21 short8 ish8;
22 t3 vec4_3;
23 bool4 bvec4 = 0;
24 int *ptr;
25 int i;
27 vec3 += vec2; // expected-error {{cannot convert between vector values of different size}}
28 vec4 += vec3; // expected-error {{cannot convert between vector values of different size}}
30 vec4 = 5.0f;
31 vec4 = (float4)5.0f;
32 vec4 = (float4)5;
33 vec4 = (float4)vec4_3;
35 ivec4 = (int4)5.0f;
36 ivec4 = (int4)5;
37 ivec4 = (int4)vec4_3;
39 i = (int)ivec4; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and integer type 'int' of different size}}
40 i = ivec4; // expected-error {{assigning to 'int' from incompatible type 'int4' (vector of 4 'int' values)}}
42 ivec4 = (int4)ptr; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and scalar type 'int *'}}
44 vec4 = (float4)vec2; // expected-error {{invalid conversion between ext-vector type 'float4' (vector of 4 'float' values) and 'float2' (vector of 2 'float' values)}}
46 ish8 += 5;
47 ivec4 *= 5;
48 vec4 /= 5.2f;
49 vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' (vector of 4 'float' values) and 'int')}}
50 ivec4 %= 4;
51 ivec4 += vec4; // expected-error {{cannot convert between vector values of different size ('int4' (vector of 4 'int' values) and 'float4' (vector of 4 'float' values))}}
52 ivec4 += (int4)vec4;
53 ivec4 -= ivec4;
54 ivec4 |= ivec4;
55 ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
57 bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
58 // expected-note {{use '|=' to turn this inequality comparison into an or-assignment}}
61 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}}
63 void inc(float2 f2) {
64 f2++; // expected-error{{cannot increment value of type 'float2' (vector of 2 'float' values)}}
65 __real f2; // expected-error{{invalid type 'float2' (vector of 2 'float' values) to __real operator}}
68 typedef enum
70 uchar_stride = 1,
71 uchar4_stride = 4,
72 ushort4_stride = 8,
73 short4_stride = 8,
74 uint4_stride = 16,
75 int4_stride = 16,
76 float4_stride = 16,
77 } PixelByteStride;
79 stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride);
80 stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride)
82 stride4 stride;
83 // This previously caused an assertion failure.
84 stride.lo = ((ulong2) x) * pixelByteStride; // no-warning
85 return stride;
88 typedef __attribute__((ext_vector_type(4))) float float32x4_t;
90 typedef float C3DVector3 __attribute__((ext_vector_type(3)));
92 extern float32x4_t vabsq_f32(float32x4_t __a);
94 C3DVector3 Func(const C3DVector3 a) {
95 return (C3DVector3)vabsq_f32((float32x4_t)a); // expected-error {{invalid conversion between ext-vector type 'float32x4_t' (vector of 4 'float' values) and 'C3DVector3' (vector of 3 'float' values)}}
98 typedef double double2 __attribute__ ((ext_vector_type(2)));
100 static void splats(int i, long l, __uint128_t t, float f, double d) {
101 short8 vs = 0;
102 int4 vi = i;
103 ulong2 vl = (unsigned long)l;
104 float2 vf = f;
105 double2 vd = d;
107 vs = 65536 + vs; // expected-warning {{implicit conversion from 'int' to 'short8' (vector of 8 'short' values) changes value from 65536 to 0}}
108 vs = vs + i; // expected-warning {{implicit conversion loses integer precision}}
109 vs = vs + 1;
110 vs = vs + 1.f; // expected-error {{cannot convert between vector values of different size}}
112 vi = l + vi; // expected-warning {{implicit conversion loses integer precision}}
113 vi = 1 + vi;
114 vi = vi + 2.0; // expected-error {{cannot convert between vector values of different size}}
115 vi = vi + 0xffffffff; // expected-warning {{implicit conversion changes signedness}}
117 vl = l + vl; // expected-warning {{implicit conversion changes signedness}}
118 vl = vl + t; // expected-warning {{implicit conversion loses integer precision}}
120 vf = 1 + vf;
121 vf = l + vf; // expected-warning {{implicit conversion from 'long' to 'float2' (vector of 2 'float' values) may lose precision}}
122 vf = 2.0 + vf;
123 vf = d + vf; // expected-warning {{implicit conversion loses floating-point precision}}
124 vf = vf + 0xffffffff; // expected-warning {{implicit conversion from 'unsigned int' to 'float2' (vector of 2 'float' values) changes value from 4294967295 to 4294967296}}
125 vf = vf + 2.1; // expected-warning {{implicit conversion loses floating-point precision}}
127 vd = l + vd; // expected-warning {{implicit conversion from 'long' to 'double2' (vector of 2 'double' values) may lose precision}}
128 vd = vd + t; // expected-warning {{implicit conversion from '__uint128_t' (aka 'unsigned __int128') to 'double2' (vector of 2 'double' values) may lose precision}}