1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -fsyntax-only -verify -fno-lax-vector-conversions -Wconversion %s 258d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman 358d29a41271d96509f464716f79b0ab2e815b6b1Nate Begemantypedef __attribute__(( ext_vector_type(2) )) float float2; 4651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestypedef __attribute__(( ext_vector_type(3) )) float float3; 558d29a41271d96509f464716f79b0ab2e815b6b1Nate Begemantypedef __attribute__(( ext_vector_type(4) )) int int4; 61bd1f6e85a011fe3129dc2898857e72741d36667Nate Begemantypedef __attribute__(( ext_vector_type(8) )) short short8; 758d29a41271d96509f464716f79b0ab2e815b6b1Nate Begemantypedef __attribute__(( ext_vector_type(4) )) float float4; 858d29a41271d96509f464716f79b0ab2e815b6b1Nate Begemantypedef float t3 __attribute__ ((vector_size (16))); 9af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenektypedef __typeof__(sizeof(int)) size_t; 10af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenektypedef unsigned long ulong2 __attribute__ ((ext_vector_type(2))); 11af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenektypedef size_t stride4 __attribute__((ext_vector_type(4))); 1258d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman 1358d29a41271d96509f464716f79b0ab2e815b6b1Nate Begemanstatic void test() { 1458d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman float2 vec2; 15651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines float3 vec3; 1658d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman float4 vec4, vec4_2; 1758d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman int4 ivec4; 181bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman short8 ish8; 1958d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman t3 vec4_3; 201bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman int *ptr; 211bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman int i; 22651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 23a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar vec3 += vec2; // expected-error {{cannot convert between vector values of different size}} 24a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar vec4 += vec3; // expected-error {{cannot convert between vector values of different size}} 2558d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman 261bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman vec4 = 5.0f; 2758d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman vec4 = (float4)5.0f; 2858d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman vec4 = (float4)5; 2958d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman vec4 = (float4)vec4_3; 3058d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman 3158d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman ivec4 = (int4)5.0f; 3258d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman ivec4 = (int4)5; 3358d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman ivec4 = (int4)vec4_3; 3458d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman 356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines i = (int)ivec4; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and integer type 'int' of different size}} 366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines i = ivec4; // expected-error {{assigning to 'int' from incompatible type 'int4' (vector of 4 'int' values)}} 371bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman 386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ivec4 = (int4)ptr; // expected-error {{invalid conversion between vector type 'int4' (vector of 4 'int' values) and scalar type 'int *'}} 391bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman 406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines vec4 = (float4)vec2; // expected-error {{invalid conversion between ext-vector type 'float4' (vector of 4 'float' values) and 'float2' (vector of 2 'float' values)}} 41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 42651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ish8 += 5; 431bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman ivec4 *= 5; 441bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman vec4 /= 5.2f; 456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' (vector of 4 'float' values) and 'int')}} 461bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman ivec4 %= 4; 47a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar 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))}} 481bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman ivec4 += (int4)vec4; 491bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman ivec4 -= ivec4; 501bd1f6e85a011fe3129dc2898857e72741d36667Nate Begeman ivec4 |= ivec4; 51a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}} 5258d29a41271d96509f464716f79b0ab2e815b6b1Nate Begeman} 530c293ea13d452c1a47a05ada5a5ee9acc69c66ccDouglas Gregor 546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestypedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}} 554b1317264037732fff3653ac6f494b124c726e1bDouglas Gregor 564b1317264037732fff3653ac6f494b124c726e1bDouglas Gregorvoid inc(float2 f2) { 576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines f2++; // expected-error{{cannot increment value of type 'float2' (vector of 2 'float' values)}} 586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines __real f2; // expected-error{{invalid type 'float2' (vector of 2 'float' values) to __real operator}} 594b1317264037732fff3653ac6f494b124c726e1bDouglas Gregor} 60af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek 61af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenektypedef enum 62af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek{ 63af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek uchar_stride = 1, 64af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek uchar4_stride = 4, 65af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek ushort4_stride = 8, 66af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek short4_stride = 8, 67af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek uint4_stride = 16, 68af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek int4_stride = 16, 69af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek float4_stride = 16, 70af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek} PixelByteStride; 71af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek 72af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenekstride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride); 73af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenekstride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride) 74af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek{ 75af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek stride4 stride; 76af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek // This previously caused an assertion failure. 77af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek stride.lo = ((ulong2) x) * pixelByteStride; // no-warning 78af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek return stride; 79af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek} 80af3b980ef367e031051afd67ca3475bb7aa32db8Ted Kremenek 81651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// rdar://16196902 82651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestypedef __attribute__((ext_vector_type(4))) float float32x4_t; 83651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 84651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestypedef float C3DVector3 __attribute__((ext_vector_type(3))); 85651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 86651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesextern float32x4_t vabsq_f32(float32x4_t __a); 87651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 88651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesC3DVector3 Func(const C3DVector3 a) { 896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 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)}} 90651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 91651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// rdar://16350802 93651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestypedef double double2 __attribute__ ((ext_vector_type(2))); 94651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 95651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstatic void splats(int i, long l, __uint128_t t, float f, double d) { 96651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines short8 vs = 0; 97651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines int4 vi = i; 98651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ulong2 vl = (unsigned long)l; 99651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines float2 vf = f; 100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines double2 vd = d; 101651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines vs = 65536 + vs; // expected-warning {{implicit conversion from 'int' to 'short8' (vector of 8 'short' values) changes value from 65536 to 0}} 103651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vs = vs + i; // expected-warning {{implicit conversion loses integer precision}} 104651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vs = vs + 1; 105a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar vs = vs + 1.f; // expected-error {{cannot convert between vector values of different size}} 106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 107651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vi = l + vi; // expected-warning {{implicit conversion loses integer precision}} 108651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vi = 1 + vi; 109a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar vi = vi + 2.0; // expected-error {{cannot convert between vector values of different size}} 110651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vi = vi + 0xffffffff; // expected-warning {{implicit conversion changes signedness}} 111651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 112651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vl = l + vl; // expected-warning {{implicit conversion changes signedness}} 113651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vl = vl + t; // expected-warning {{implicit conversion loses integer precision}} 114651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 115651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = 1 + vf; 116651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = l + vf; 117651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = 2.0 + vf; 118651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = d + vf; // expected-warning {{implicit conversion loses floating-point precision}} 119651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = vf + 0xffffffff; 120651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vf = vf + 2.1; // expected-warning {{implicit conversion loses floating-point precision}} 121651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 122651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vd = l + vd; 123651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines vd = vd + t; 124651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 125