summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-3778.c
blob: 56ed5ffae235a295d6dd84f87e5c823c95897512 (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
/** bug-3778.c: Incorrect top byte on 24-bit function pointers
*/

#include <testfwk.h>

int j;

#if defined(__SDCC_stm8) && defined(__SDCC_MODEL_LARGE) // Fill lower 32KB of flash, so f1 or f2 is above 0x10000.
#define ARRAYSIZE 32000
long k;
void dummyfunc(void)
{
	switch(k)
	{
	case 1:
		j = (j + 1) % (j - 1);
	case 2:
		j = (j - 1) % (j + 1);
	case 3:
		j = (j + 1) % (j + 1);
	case 4:
		j = (j - 1) % (j - 1);
	case 5:
		j = (j + 2) % (j - 2);
	case 6:
		j = (j - 2) % (j + 2);
	}
}
#else
#define ARRAYSIZE 1
#endif

const char c[ARRAYSIZE];

void f1(char c, int i) __reentrant
{
	j = c + i;
}

void g1(void(*ptr)(char, int) __reentrant)
{
	(*ptr)(1, 2); // Topmost byte of ptr incorrectly assumed to be 0.
}

void h1(void)
{
	g1(&f1);
}

void f2(char c, int i) __reentrant
{
	j = c + i;
}

void g2(void(*ptr)(char, int) __reentrant)
{
	(*ptr)(2, 3); // Topmost byte of ptr incorrectly assumed to be 0.
}

void h2(void)
{
	g2(&f2);
}

void
testBug(void)
{	
	h1();
	ASSERT(j == 3);
	h2();
	ASSERT(j == 5);
}