summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-3779.c
blob: bf4a58f1b91711707d0039a8d5e6e61dbb29b762 (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
43
44
45
46
/** bug-3779.c: code generation for sm83 could store a temporary in l, then set up hl for stack access, overwriting the temporary.
*/

#include <testfwk.h>

struct State {
    unsigned short a;
    unsigned char b;
};
static struct State state;

static char glob_var;

#ifdef __SDCC_sm83
static __sfr __at(0xff00) reg; // Use LCD control register for this test, since all its bits are read/write.
#else
unsigned char reg;
#endif

void m(void)
{
    state.b = 0;

    if (glob_var) {
        if (glob_var) {
            state.a += 1;
        } 
        if (glob_var) {
            state.b = 0;
        }

        unsigned char foo = state.a >> 1;
        foo -= reg;
        reg = foo;
    }
}

void testBug(void)
{
    reg = 0x00;
    glob_var = 1;
    state.a = 1;
    m();
    ASSERT(reg == 1);
}