summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2932.c
blob: d3869010615e972c578846af4a9ec3982e20323d (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
   bug-932.c

   For a basic block that consists of only a call two al __smallc function with at least two parameters,
   the sch pointer of a basic block could be wrong, resulting in incorrect live-range for some corner cases,
   which in turn for some corner cases could result in live-range separation incorrectly assuming an
   iCode to be dead, which resulted in changes to the iCode that triggered a segfault in the z80 register allocator.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma disable_warning 85
#endif

int fg(void *fp)
{
    volatile int i = 1;
    return i;
}

extern int fp(int c, void *fp) __smallc
{
    return -1;
}

void *infile, *outfile;
static unsigned long int textsize = 0;

int error;

static void Error(const char *message)
{
    error++;
}

#define THRESHOLD   2

static int DecodeChar(void)
{
    volatile int i = 255;
    return i;
}

static void Decode(void)
{
    int j, k, c;
    unsigned long int  count;

    textsize = fg(infile);

    for (count = 0; count < textsize; ) {
        c = DecodeChar();
        if (c < 256) {
            if (fp(c, outfile) == -1) {
                Error("");
            }
            count++;
        } else {
            j = c - 255 + THRESHOLD;
            for (k = 0; k < j; k++) {
                count++;
            }
        }
    }
}

void testBug(void)
{
    error = 0;
    Decode();
    ASSERT (error == 1);
}