summaryrefslogtreecommitdiff
path: root/support/regression/tests/bigstack.c.in
blob: 2cd80b84b082ea1021c37dda6e0c5bb2bf20e4c6 (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
/* Test parameters for functions that use a large stack for local variables.
   There is apotential a bug where the stack adjustment at function entry overwrites register parameters.
   To reproduce, we need a large stack (so registers are used for stack adjustment), and
   parameters that are small enough to be allocated to registers, but big enough that these
   registers have the smae width as teh stack pointer.

   type1: unsigned char, unsigned int, unsigned long
   type2: unsigned char, unsigned int, unsigned long
 */

#include <testfwk.h>

volatile {type1} int1;
volatile {type2} int2;

#ifdef __SDCC_pdk14
#define ARRAYSIZE 30
#elif defined (__SDCC_pdk15) || defined (__SDCC_mcs51) || defined (__SDCC_mos6502) || defined (__SDCC_mos65c02)
#define ARRAYSIZE 60
#else
#define ARRAYSIZE 780 // Needs to be bigger than 266 to reliably trigger conditions for stm8, also sufficient for z80
#endif

void g(unsigned char *);

void f({type1} par1, {type2} par2)
{
	unsigned char array[ARRAYSIZE];
	g(array);
	int1 = par1;
	int2 = par2;
	ASSERT(array[0] == 0 && array[ARRAYSIZE - 1] == (unsigned char)(ARRAYSIZE - 1));
}

void g(unsigned char *array)
{
	array[0] = 0; array[ARRAYSIZE - 1] = (unsigned char)(ARRAYSIZE - 1);
}

void
testStack(void)
{
	f(23, 42);
	ASSERT (int1 == ({type1})23);
	ASSERT (int2 == ({type2})42);
	f(0xa5a5a5, 0x5a5a5a);
	ASSERT (int1 == ({type1})0xa5a5a5);
	ASSERT (int2 == ({type2})0x5a5a5a);
}