Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3332.c
blob57565e58fd87787d5e6cf0bf397ddf9a14612be4
1 /*
2 bug-3322.c
3 A bug in __naked __sdcccall(N) functions (as opposed to __sdcccall(0) __naked, which worked)
4 */
6 #include <testfwk.h>
8 #pragma disable_warning 85
10 #if defined(__SDCC_stm8) || defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_z80n) || defined(__SDCC_sm83)
11 #define NAKED __naked
12 #define SDCCCALL0 __sdcccall(0)
13 #else
14 #define NAKED
15 #define SDCCCALL0
16 #endif
18 static unsigned char test_2(const unsigned char foo) NAKED SDCCCALL0 {
19 #if defined(__SDCC_stm8) && defined(__SDCC_MODEL_MEDIUM)
20 __asm
21 ld a, (0x03, sp)
22 inc a
23 ret
24 __endasm;
25 #elif defined(__SDCC_stm8) && defined(__SDCC_MODEL_LARGE)
26 __asm
27 ld a, (0x04, sp)
28 inc a
29 retf
30 __endasm;
31 #elif defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_z80n)
32 __asm
33 ld iy, #2
34 add iy, sp
35 ld l, 0 (iy)
36 inc l
37 ret
38 __endasm;
39 #elif defined(__SDCC_sm83)
40 __asm
41 ldhl sp, #2
42 ld e, (hl)
43 inc e
44 ret
45 __endasm;
46 #else
47 return foo + 1;
48 #endif
51 void testBug(void) {
52 volatile unsigned char bar = test_2(23);
53 ASSERT(bar == 24);