Menu

#2881 [Z80][SDCC 3.8.0] Stack allocation trashes register-passed parameter

closed-fixed
None
Z80
5
2019-03-16
2019-03-14
AHelper
No

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
2 Attachments

Discussion

  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Philipp Klaus Krause

    Fixed in [r11106].

    Philipp

     

Log in to post a comment.

MongoDB Logo MongoDB