Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3626.c
blobdac7f00f795ba1f31e36ca17437578761c9fcc3e
1 /* bug-3626.c
2 For optimization of jump table conditions, a computeOnly flag was ignored in common subexpression elimination,
3 resulting in an optimization being triggered incorrectly.
4 */
6 #include <testfwk.h>
8 #include <setjmp.h>
10 jmp_buf buf;
12 int p(int c)
14 static int i = '0';
15 ASSERT (c == i++);
16 if (c == '5')
17 longjmp (buf, 1);
20 void m(void)
22 unsigned char state = 0;
23 while (1) {
24 p(state + '0');
25 switch (state) { // Condition in this switch statement was wrongly replaced by constant 0.
26 case 0: state = 1; break;
27 case 1: state = 2; break;
28 case 2: state = 3; break;
29 case 3: state = 4; break;
30 case 4: state = 5; break;
31 default: state = 0; break;
36 void
37 testBug (void)
39 if (!setjmp (buf))
40 m ();