offset of (Actor)[hit].hit_1_ptr is calculated into HL. then SDCC fetches value of stack-allocated variable to make conditional jump, that spoils HL. then it adds address of actors array to HL, assuming it still contains offset:
;test9.c:45: TestFn2(&actors[hit].hit_1_ptr);
ld e, l
ld d, #0x00
ld l, e
ld h, d
add hl, hl
add hl, de
add hl, hl
;test9.c:44: if (projectiles[i].col_group == 2) {
ldhl sp, #0
ld a, (hl)
sub a, #0x02
jr NZ, 00104$
;test9.c:45: TestFn2(&actors[hit].hit_1_ptr);
ld de, #_actors
add hl, de
that behaviour is very fragile. for example --max-allocs-per-node 50000 fixes that by eliminating stack-allocated projectiles[i].col_group.
version:
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.0.3 #11916 (MINGW64)
commandline:
sdcc -mgbz80 --fsigned-char --no-std-crt0 -I ..\..\gbdk\include -I ..\..\gbdk\include\asm -I src\include -c test9.c -o build\test9.rel
I haven't been able to reproduce this on my Debian GNU/Linux testing system so far, but will keep looking into it further.
P.S.: In [r11923], I added a test, which I hope will trigger this bug on some of the systems in the compile farm.
P.P.S.: Could you add the test.asm when compiling with --fverbose-asm --no-peep --i-code-in-asm?
Last edit: Philipp Klaus Krause 2020-10-26
how can i help you here? maybe provide some additional info?
generates:
with disabled PH rules:
what is the code here, generated by linux port, i wonder?
full asm in attach below:
Last edit: Tony Pavlov 2020-10-26
This should be fixed in [r11924]. Please test.
On my Debian GNU/Linux testing system, projectiles[i].col_group got allocated to register b.
just released r11925 works perfect! thank you, Philipp!