summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-3626.c
blob: dac7f00f795ba1f31e36ca17437578761c9fcc3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* bug-3626.c
   For optimization of jump table conditions, a computeOnly flag was ignored in common subexpression elimination,
   resulting in an optimization being triggered incorrectly.
*/

#include <testfwk.h>

#include <setjmp.h>

jmp_buf buf;

int p(int c)
{
	static int i = '0';
	ASSERT (c == i++);
	if (c == '5')
		longjmp (buf, 1);
}

void m(void)
{
    unsigned char state = 0;
    while (1) {
        p(state + '0');
        switch (state) { // Condition in this switch statement was wrongly replaced by constant 0.
            case  0: state = 1; break;
            case  1: state = 2; break;
            case  2: state = 3; break;
            case  3: state = 4; break;
            case  4: state = 5; break;
            default: state = 0; break;
        }
    }
}

void 
testBug (void)
{
	if (!setjmp (buf))
		m ();
}