struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr44468.c
blob8cc586a75148b0794ed945e3546ecec1b31bdea2
1 /*
2 pr44468.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <stddef.h>
13 struct S {
14 int i;
15 int j;
17 struct R {
18 int k;
19 struct S a;
21 struct Q {
22 float k;
23 struct S a;
25 struct Q s;
26 int
27 test1 (void *q)
29 struct S *b = (struct S *)((char *)q + sizeof (int));
30 s.a.i = 0;
31 b->i = 3;
32 return s.a.i;
34 int
35 test2 (void *q)
37 struct S *b = &((struct R *)q)->a;
38 s.a.i = 0;
39 b->i = 3;
40 return s.a.i;
42 int
43 test3 (void *q)
45 s.a.i = 0;
46 ((struct S *)((char *)q + sizeof (int)))->i = 3;
47 return s.a.i;
50 void
51 testTortureExecute (void)
53 #if !(defined (__GNUC__) && defined (__GNUC_MINOR__) && (__GNUC__ < 5 && __GNUC_MINOR__ < 5))
54 if (sizeof (float) != sizeof (int)
55 || offsetof (struct R, a) != sizeof (int)
56 || offsetof (struct Q, a) != sizeof (int))
57 return;
58 s.a.i = 1;
59 s.a.j = 2;
60 if (test1 ((void *)&s) != 3)
61 ASSERT (0);
62 s.a.i = 1;
63 s.a.j = 2;
64 if (test2 ((void *)&s) != 3)
65 ASSERT (0);
66 s.a.i = 1;
67 s.a.j = 2;
68 if (test3 ((void *)&s) != 3)
69 ASSERT (0);
70 return;
71 #endif