1 /*
2    bug-932.c
3 
4    For a basic block that consists of only a call two al __smallc function with at least two parameters,
5    the sch pointer of a basic block could be wrong, resulting in incorrect live-range for some corner cases,
6    which in turn for some corner cases could result in live-range separation incorrectly assuming an
7    iCode to be dead, which resulted in changes to the iCode that triggered a segfault in the z80 register allocator.
8  */
9 
10 #include <testfwk.h>
11 
12 #ifdef __SDCC
13 #pragma disable_warning 85
14 #endif
15 
16 #if !(defined(__SDCC_z80) || defined(__SDCC_gbz80) || defined(__SDCC_z180) || defined(__SDCC_r2k))
17 #define __smallc
18 #endif
19 
fg(void * fp)20 int fg(void *fp)
21 {
22     volatile int i = 1;
23     return i;
24 }
25 
fp(int c,void * fp)26 extern int fp(int c, void *fp) __smallc
27 {
28     return -1;
29 }
30 
31 void *infile, *outfile;
32 static unsigned long int textsize = 0;
33 
34 int error;
35 
Error(const char * message)36 static void Error(const char *message)
37 {
38     error++;
39 }
40 
41 #define THRESHOLD   2
42 
DecodeChar(void)43 static int DecodeChar(void)
44 {
45     volatile int i = 255;
46     return i;
47 }
48 
Decode(void)49 static void Decode(void)
50 {
51     int j, k, c;
52     unsigned long int  count;
53 
54     textsize = fg(infile);
55 
56     for (count = 0; count < textsize; ) {
57         c = DecodeChar();
58         if (c < 256) {
59             if (fp(c, outfile) == -1) {
60                 Error("");
61             }
62             count++;
63         } else {
64             j = c - 255 + THRESHOLD;
65             for (k = 0; k < j; k++) {
66                 count++;
67             }
68         }
69     }
70 }
71 
testBug(void)72 void testBug(void)
73 {
74     error = 0;
75     Decode();
76     ASSERT (error == 1);
77 }
78 
79