struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-20111208-1.c
blobf44fdb6e3c2659e7536c6ec6ea10f7984d4a2787
1 /*
2 20111208-1.c from the execute part of the gcc torture suite.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <stdint.h>
12 #include <string.h>
14 #if !(defined (__GNUC__) && __GNUC__ < 5)
15 /* PR tree-optimization/51315 */
16 /* Reported by Jurij Smakov <jurij@wooyd.org> */
18 int a;
20 static void
21 do_something (int item)
23 a = item;
26 int
27 pack_unpack (char *s, char *p)
29 char *send, *pend;
30 char type;
31 int integer_size;
33 send = s + strlen (s);
34 pend = p + strlen (p);
36 while (p < pend)
38 type = *p++;
40 switch (type)
42 case 's':
43 integer_size = 2;
44 goto unpack_integer;
46 case 'l':
47 integer_size = 4;
48 goto unpack_integer;
50 unpack_integer:
51 switch (integer_size)
53 case 2:
55 union
57 int16_t i;
58 char a[sizeof (int16_t)];
61 memcpy (v.a, s, sizeof (int16_t));
62 s += sizeof (int16_t);
63 do_something (v.i);
65 break;
67 case 4:
69 union
71 int32_t i;
72 char a[sizeof (int32_t)];
75 memcpy (v.a, s, sizeof (int32_t));
76 s += sizeof (int32_t);
77 do_something (v.i);
79 break;
81 break;
84 return (int) *s;
86 #endif
88 void
89 testTortureExecute (void)
91 #if !(defined (__GNUC__) && __GNUC__ < 5)
92 int n = pack_unpack ("\200\001\377\376\035\300", "sl");
93 if (n != 0)
94 ASSERT (0);
95 return;
96 #endif