1 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -fsyntax-only -verify -fno-lax-vector-conversions -Wconversion %s 2 3 typedef __attribute__(( ext_vector_type(2) )) float float2; 4 typedef __attribute__(( ext_vector_type(3) )) float float3; 5 typedef __attribute__(( ext_vector_type(4) )) int int4; 6 typedef __attribute__(( ext_vector_type(8) )) short short8; 7 typedef __attribute__(( ext_vector_type(4) )) float float4; 8 typedef float t3 __attribute__ ((vector_size (16))); 9 typedef __typeof__(sizeof(int)) size_t; 10 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2))); 11 typedef size_t stride4 __attribute__((ext_vector_type(4))); 12 13 static void test() { 14 float2 vec2; 15 float3 vec3; 16 float4 vec4, vec4_2; 17 int4 ivec4; 18 short8 ish8; 19 t3 vec4_3; 20 int *ptr; 21 int i; 22 23 vec3 += vec2; // expected-error {{can't convert between vector values of different size}} 24 vec4 += vec3; // expected-error {{can't convert between vector values of different size}} 25 26 vec4 = 5.0f; 27 vec4 = (float4)5.0f; 28 vec4 = (float4)5; 29 vec4 = (float4)vec4_3; 30 31 ivec4 = (int4)5.0f; 32 ivec4 = (int4)5; 33 ivec4 = (int4)vec4_3; 34 35 i = (int)ivec4; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and integer type 'int' of different size}} 36 i = ivec4; // expected-error {{assigning to 'int' from incompatible type 'int4' (vector of 4 'int' values)}} 37 38 ivec4 = (int4)ptr; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and scalar type 'int *'}} 39 40 vec4 = (float4)vec2; // expected-error {{invalid conversion between ext-vector type 'float4' (vector of 4 'float' values) and 'float2' (vector of 2 'float' values)}} 41 42 ish8 += 5; 43 ivec4 *= 5; 44 vec4 /= 5.2f; 45 vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' (vector of 4 'float' values) and 'int')}} 46 ivec4 %= 4; 47 ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('int4' (vector of 4 'int' values) and 'float4' (vector of 4 'float' values))}} 48 ivec4 += (int4)vec4; 49 ivec4 -= ivec4; 50 ivec4 |= ivec4; 51 ivec4 += ptr; // expected-error {{can't convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}} 52 } 53 54 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}} 55 56 void inc(float2 f2) { 57 f2++; // expected-error{{cannot increment value of type 'float2' (vector of 2 'float' values)}} 58 __real f2; // expected-error{{invalid type 'float2' (vector of 2 'float' values) to __real operator}} 59 } 60 61 typedef enum 62 { 63 uchar_stride = 1, 64 uchar4_stride = 4, 65 ushort4_stride = 8, 66 short4_stride = 8, 67 uint4_stride = 16, 68 int4_stride = 16, 69 float4_stride = 16, 70 } PixelByteStride; 71 72 stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride); 73 stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride) 74 { 75 stride4 stride; 76 // This previously caused an assertion failure. 77 stride.lo = ((ulong2) x) * pixelByteStride; // no-warning 78 return stride; 79 } 80 81 // rdar://16196902 82 typedef __attribute__((ext_vector_type(4))) float float32x4_t; 83 84 typedef float C3DVector3 __attribute__((ext_vector_type(3))); 85 86 extern float32x4_t vabsq_f32(float32x4_t __a); 87 88 C3DVector3 Func(const C3DVector3 a) { 89 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)}} 90 } 91 92 // rdar://16350802 93 typedef double double2 __attribute__ ((ext_vector_type(2))); 94 95 static void splats(int i, long l, __uint128_t t, float f, double d) { 96 short8 vs = 0; 97 int4 vi = i; 98 ulong2 vl = (unsigned long)l; 99 float2 vf = f; 100 double2 vd = d; 101 102 vs = 65536 + vs; // expected-warning {{implicit conversion from 'int' to 'short8' (vector of 8 'short' values) changes value from 65536 to 0}} 103 vs = vs + i; // expected-warning {{implicit conversion loses integer precision}} 104 vs = vs + 1; 105 vs = vs + 1.f; // expected-error {{can't convert between vector values of different size}} 106 107 vi = l + vi; // expected-warning {{implicit conversion loses integer precision}} 108 vi = 1 + vi; 109 vi = vi + 2.0; // expected-error {{can't convert between vector values of different size}} 110 vi = vi + 0xffffffff; // expected-warning {{implicit conversion changes signedness}} 111 112 vl = l + vl; // expected-warning {{implicit conversion changes signedness}} 113 vl = vl + t; // expected-warning {{implicit conversion loses integer precision}} 114 115 vf = 1 + vf; 116 vf = l + vf; 117 vf = 2.0 + vf; 118 vf = d + vf; // expected-warning {{implicit conversion loses floating-point precision}} 119 vf = vf + 0xffffffff; 120 vf = vf + 2.1; // expected-warning {{implicit conversion loses floating-point precision}} 121 122 vd = l + vd; 123 vd = vd + t; 124 } 125