Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bigstack.c.in
blob2cd80b84b082ea1021c37dda6e0c5bb2bf20e4c6
1 /* Test parameters for functions that use a large stack for local variables.
2 There is apotential a bug where the stack adjustment at function entry overwrites register parameters.
3 To reproduce, we need a large stack (so registers are used for stack adjustment), and
4 parameters that are small enough to be allocated to registers, but big enough that these
5 registers have the smae width as teh stack pointer.
7 type1: unsigned char, unsigned int, unsigned long
8 type2: unsigned char, unsigned int, unsigned long
9 */
11 #include <testfwk.h>
13 volatile {type1} int1;
14 volatile {type2} int2;
16 #ifdef __SDCC_pdk14
17 #define ARRAYSIZE 30
18 #elif defined (__SDCC_pdk15) || defined (__SDCC_mcs51) || defined (__SDCC_mos6502) || defined (__SDCC_mos65c02)
19 #define ARRAYSIZE 60
20 #else
21 #define ARRAYSIZE 780 // Needs to be bigger than 266 to reliably trigger conditions for stm8, also sufficient for z80
22 #endif
24 void g(unsigned char *);
26 void f({type1} par1, {type2} par2)
28 unsigned char array[ARRAYSIZE];
29 g(array);
30 int1 = par1;
31 int2 = par2;
32 ASSERT(array[0] == 0 && array[ARRAYSIZE - 1] == (unsigned char)(ARRAYSIZE - 1));
35 void g(unsigned char *array)
37 array[0] = 0; array[ARRAYSIZE - 1] = (unsigned char)(ARRAYSIZE - 1);
40 void
41 testStack(void)
43 f(23, 42);
44 ASSERT (int1 == ({type1})23);
45 ASSERT (int2 == ({type2})42);
46 f(0xa5a5a5, 0x5a5a5a);
47 ASSERT (int1 == ({type1})0xa5a5a5);
48 ASSERT (int2 == ({type2})0x5a5a5a);