Debian Codegraph @

gcc/testsuite/c-c++-common/torture/vector-subscript-2.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-fno-common" { target hppa*-*-hpux* } } */
3 #define vector __attribute__((vector_size(sizeof(int)*4) ))
4
5 /* Check to make sure that we extract and insert the vector at the same
6 location for vector subscripting (with constant indexes) and
7 that vectors layout are the same as arrays. */
8
9 struct TV4
10 {
11 vector int v;
12 };
13
14 typedef struct TV4 MYV4;
15
16 static inline MYV4 myfunc2( int x, int y, int z, int w )
17 {
18 MYV4 temp;
19 temp.v[0] = x;
20 temp.v[1] = y;
21 temp.v[2] = z;
22 temp.v[3] = w;
23 return temp;
24 }
25 MYV4 val3;
26 __attribute__((noinline)) void modify (void)
27 {
28 val3 = myfunc2( 1, 2, 3, 4 );
29 }
30 int main( int argc, char* argv[] )
31 {
32 int a[4];
33 int i;
34
35 /* Set up the vector. */
36 modify();
37
38 /* Check the vector via the global variable. */
39 if (val3.v[0] != 1)
40 __builtin_abort ();
41 if (val3.v[1] != 2)
42 __builtin_abort ();
43 if (val3.v[2] != 3)
44 __builtin_abort ();
45 if (val3.v[3] != 4)
46 __builtin_abort ();
47
48 vector int a1 = val3.v;
49
50 /* Check the vector via a local variable. */
51 if (a1[0] != 1)
52 __builtin_abort ();
53 if (a1[1] != 2)
54 __builtin_abort ();
55 if (a1[2] != 3)
56 __builtin_abort ();
57 if (a1[3] != 4)
58 __builtin_abort ();
59
60 __builtin_memcpy(a, &val3, sizeof(a));
61 /* Check the vector via copying it to an array. */
62 for(i = 0; i < 4; i++)
63 if (a[i] != i+1)
64 __builtin_abort ();
65
66
67 return 0;
68 }
69