If a stack allocation of sufficient size emits a ld hl, #nn \ add hl, sp, a function using __z88dk_fastcall will have HL trashed.
Reproduction:
int test(int test) __z88dk_fastcall
{
char buffer[10];
buffer; // Simulating actual stack usage
return test + test;
}
...compiled with...
sdcc -mz80 -c bug_fastcall.c -o bug_fastcall.rel
...emits...
;bug_fastcall.c:1: int test(int test) __z88dk_fastcall
; ---------------------------------
; Function test
; ---------------------------------
_test::
ld hl, #-10
add hl, sp
ld sp, hl
;bug_fastcall.c:5: return test + test;
add hl, hl
;bug_fastcall.c:6: }
ld iy, #10
add iy, sp
ld sp, iy
ret
As seen above, HL isn't being preserved when a stack allocation is performed.
Version information:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.8.0 #10562 (MINGW64)
published under GNU General Public License (GPL)
Win 10 x64 1803
Fixed in [r11106].
Philipp