summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-3593.c
blob: e61285b0e69ce3a0fbc3f550072d619871b3a1a7 (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
/* bug-3593.c
   A bug in a mos6502 peephole rule.
 */

#include <testfwk.h>

#pragma disable_warning 85

static unsigned char bug(unsigned char a, unsigned char dummy) // The dummy parameter is set in the caller using lda, which changes the flags after setiing a.
{
        unsigned char i = 0;

        if (a == 0) { // Peephole rule eliminated a load here, desppite this changing the flags still needed for a subsequent conditional branch.
                return 0;
        }

        while (i != a) {
                ++i;
        }

        return 1;
}

void
testBug (void)
{
	ASSERT (bug (0, 1) == 0);
	ASSERT (bug (1, 0) == 1);
}