ext_vector_components.c revision 353417af9d254d4fd0eb7d0a3ff71c4d8594ac58
1// RUN: clang -fsyntax-only -verify %s
2
3typedef __attribute__(( ext_vector_type(2) )) float float2;
4typedef __attribute__(( ext_vector_type(3) )) float float3;
5typedef __attribute__(( ext_vector_type(4) )) float float4;
6
7static void test() {
8    float2 vec2, vec2_2;
9    float3 vec3;
10    float4 vec4, vec4_2;
11    float f;
12
13    vec2.z; // expected-error {{vector component access exceeds type 'float2'}}
14    vec2.xyzw; // expected-error {{vector component access exceeds type 'float2'}}
15    vec4.xyzw; // expected-warning {{expression result unused}}
16    vec4.xyzc; // expected-error {{illegal vector component name 'c'}}
17    vec4.s01z; // expected-error {{illegal vector component name 'z'}}
18    vec2 = vec4.s01; // legal, shorten
19
20    vec3 = vec4.xyz; // legal, shorten
21    f = vec2.x; // legal, shorten
22    f = vec4.xy.x; // legal, shorten
23
24    vec2 = vec3.hi; // expected-error {{vector component access invalid for odd-sized type 'float3'}}
25
26    vec4_2.xyzx = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
27    vec4_2.xyzz = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
28    vec4_2.xyyw = vec4.xyzw; // expected-error {{vector is not assignable (contains duplicate components)}}
29    vec2.x = f;
30    vec2.xx = vec2_2.xy; // expected-error {{vector is not assignable (contains duplicate components)}}
31    vec2.yx = vec2_2.xy;
32    vec4 = (float4){ 1,2,3,4 };
33    vec4.xy.w; // expected-error {{vector component access exceeds type 'float2'}}
34    vec4.s06; // expected-error {{vector component access exceeds type 'float4'}}
35}
36