Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-2632.c
blob3be48b2e13dbb325e5f4edafc832279f277d2f99
1 /*
2 bug-2632.c
4 A temporary in an optimization for address calculations for array accesses used a signed 8-bit type to hold values up to 255, and then cast the result to a signed int.
5 */
7 #include <testfwk.h>
9 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
10 unsigned char testArr255[255]; // Fails
11 unsigned char testArr256[256]; // Succeeds
13 void g(char *p)
15 *p = 0;
18 void f(void)
20 int i, j;
22 i = 5;
23 for (j = 7; j < 10; j++)
25 g(&testArr255[i * 24 + j]);
26 g(&testArr256[i * 24 + j]);
29 #endif
31 void testBug(void)
33 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
34 for(unsigned int i = 0; i < 250; i++)
35 testArr255[i] = i;
36 for(unsigned int i = 0; i < 250; i++)
37 testArr256[i] = i + 1;
39 f();
41 for(unsigned int i = 0; i < 127; i++)
42 ASSERT(testArr255[i] == i);
43 for(unsigned int i = 0; i < 127; i++)
44 ASSERT(testArr256[i] == i + 1);
45 for(unsigned int i = 127; i < 130; i++)
46 ASSERT(testArr255[i] == 0);
47 for(unsigned int i = 127; i < 130; i++)
48 ASSERT(testArr256[i] == 0);
49 for(unsigned int i = 130; i < 250; i++)
50 ASSERT(testArr255[i] == i);
51 for(unsigned int i = 130; i < 250; i++)
52 ASSERT(testArr256[i] == i + 1);
53 #endif