SDCC Version: SDCC : z80/gbz80 4.1.6 #12539 (Linux)
When the z80 port (and perhaps GBZ80, see below) is evaluating the following peephole rule:
replace restart {
jp %1, %5
} by {
; common peephole 163 changed absolute to relative conditional jump.
jr %1, %5
} if same(%1 'C' 'NC' 'NZ' 'Z'), labelInRange(%5)
It calls labelInRange() -> pcDistance(). When pcDistance reaches the start of a banked function call such as:
b_some_banked_func = 2
_some_banked_func::
Then z80instructionSize() (called as getsize() by pcDistance()) will emit the info/warning below:
min_example.c:20: info 218: z80instructionSize() failed to parse line node, assuming 999 bytes
'b_some_banked_func = 2'
It seems like the function bank number should probably get filtered out. It's not clear whether that should be in pcDistance() of SDCCpeeph.c, in z80instructionSize() of z80/peep.c, or elsewhere.
Attached is a minimal example to reproduce it (needs to create a jp near the start of a banked function call). Here is the command line to build:
sdcc -mz80 --no-std-crt0 --fsigned-char --use-stdout -Wa-pogn -DINT_16_BITS -D__LCC__ --verbose -c min_example.c -o min_example.o
Looking into this turned up a possible peephole instruction parsing bug that masks the issue for GBZ80:
For unmodified builds of SDCC the above warning/info will not occur. That doesn't happen due to what looks like a operator precedence bug in the peephole parsing code:
if(IS_GB || IS_Z80N && ISINST(pl->line, "swap"))
return(2);
This code will always exit returning "2" if the target is GB, even though it looks like the intention is instead to exit and return if the "swap" instruction is found and the target is GB or z80N. Which means GBZ80 will never reach the "unrecognized instruction" handler at the bottom of the function, nor the ".db, .dw, byte and word" size handlers in between.
if((IS_GB || IS_Z80N) && ISINST(pl->line, "swap"))
return(2);
The issue in handling of Z80N / SM83 swap is fixed in [r12680].
Great, thank you!
It rather belongs into SDCCpeeph.c, that’s general ASxxxx syntax. But not directly into pcDistance, we probably need to create a new attribute similar to
isDebugand such.Fixed in [r13187]
Related
Commit: [r13187]
Thanks!