This one came via z88dk support issue, but I've reproduced with SVN #12016.
Code is attached.
Command line is:
sdcc -mz80 -S --reserve-regs-iy str.c
Generated code is:
_main::
;str.c:20: storage.abyte1 = 1;
ld hl, #_storage
ld (hl), #0x01
;str.c:21: storage.abyte2 = 10;
ld de, #_storage+0
ld hl, #(_storage + 0x0001)
ld (hl), #0x0a
;str.c:24: storage.aint = srcInt;
;str.c:23: if (flag) {
ld a, (#_flag)
or a, a
jr Z, 00102$
;str.c:24: storage.aint = srcInt;
ld de, #(_storage + 0x0002)
ld hl, #_srcInt
ld a, (hl)
ld (de), a
inc de
inc hl
ld a, (hl)
ld (de), a
;str.c:25: fn1(&storage);
ex de, hl
;str.c:27: return;
jp _fn1
00102$:
;str.c:30: storage.aint = 1;
ld hl, #0x0001
ld ((_storage + 0x0002)), hl
;str.c:31: fn1(&storage);
ex de, hl
;str.c:32: }
jp _fn1
At str.c:25 de no longer holds the address of storage so the hl being passed into fn1() as a parameter is incorrect. Compiling without --reserve-regs-iy seems to generate correct code since de is preserved from the load at str.c:21
Fixed in [r12017]