struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr20100-1.c
blob564369ea81a6b752919826b18771a17d6d451e0b
1 /*
2 pr20100-1.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 /* PR tree-optimization/20100
12 Pure function being treated as const.
13 Author: Hans-Peter Nilsson. */
15 static unsigned short g = 0;
16 static unsigned short p = 0;
17 unsigned char e;
19 static unsigned short
20 next_g (void)
22 return g == e - 1 ? 0 : g + 1;
25 static unsigned short
26 curr_p (void)
28 return p;
31 static unsigned short
32 inc_g (void)
34 return g = next_g ();
37 static unsigned short
38 curr_g (void)
40 return g;
43 static char
44 ring_empty (void)
46 if (curr_p () == curr_g ())
47 return 1;
48 else
49 return 0;
52 char
53 frob (unsigned short a, unsigned short b)
55 g = a;
56 p = b;
57 inc_g ();
58 return ring_empty ();
61 unsigned short
62 get_n (void)
64 unsigned short n = 0;
65 unsigned short org_g;
66 org_g = curr_g ();
67 while (!ring_empty () && n < 5)
69 inc_g ();
70 n++;
73 return n;
76 void
77 testTortureExecute (void)
79 e = 3;
80 if (frob (0, 2) != 0 || g != 1 || p != 2 || e != 3
81 || get_n () != 1
82 || g != 2 || p != 2)
83 ASSERT (0);
84 return;