ext_vector_casts.c 4.9 KB

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