xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/vector-init.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc //typedef __attribute__(( ext_vector_type(4) ))  float float4;
4f4a2713aSLionel Sambuc typedef float float4 __attribute__((vector_size(16)));
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc float4 foo2 = (float4){ 1.0, 2.0, 3.0, 4.0 , 5.0 }; // expected-warning{{excess elements in vector initializer}}
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
11f4a2713aSLionel Sambuc int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3 ? 1 : -1];
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
14f4a2713aSLionel Sambuc                      9.0 }; // expected-warning {{excess elements in array initializer}}
15f4a2713aSLionel Sambuc 
16f4a2713aSLionel Sambuc float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0,
17f4a2713aSLionel Sambuc                      9.0 }; // expected-warning {{excess elements in array initializer}}
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc // PR5650
f1(void)20f4a2713aSLionel Sambuc __attribute__((vector_size(16))) float f1(void) {
21f4a2713aSLionel Sambuc   __attribute__((vector_size(16))) float vec = {0.0f, 0.0f, 0.0f};
22f4a2713aSLionel Sambuc   return(vec);
23f4a2713aSLionel Sambuc }
24f4a2713aSLionel Sambuc 
f2(float a1)25f4a2713aSLionel Sambuc __attribute__((vector_size(16))) float f2(
26f4a2713aSLionel Sambuc     __attribute__((vector_size(16))) float a1) {
27f4a2713aSLionel Sambuc   return(a1);
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc 
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc // PR5265
33f4a2713aSLionel Sambuc typedef float __attribute__((ext_vector_type (3))) float3;
34f4a2713aSLionel Sambuc int test2[sizeof(float3) == sizeof(float4) ? 1 : -1];
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc // rdar://problem/8345836
37f4a2713aSLionel Sambuc typedef long long __attribute__((vector_size(16))) longlong2;
38f4a2713aSLionel Sambuc typedef short __attribute__((vector_size(16))) short8;
39f4a2713aSLionel Sambuc typedef short __attribute__((vector_size(8))) short4;
test3()40f4a2713aSLionel Sambuc void test3() {
41f4a2713aSLionel Sambuc   extern short8 test3_helper(void);
42f4a2713aSLionel Sambuc   longlong2 arr1[2] = { test3_helper(), test3_helper() };
43*0a6a1f1dSLionel Sambuc   short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' (vector of 4 'short' values) with an expression of incompatible type 'short8' (vector of 8 'short' values)}}
44f4a2713aSLionel Sambuc }
45