Menu

#3280 Warning/info: z80instructionSize() failed to parse line node, assuming 999 bytes b_some_banked_func = 2

closed-fixed
nobody
other
5
2022-03-10
2021-09-13
bbbbbr
No

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);
1 Attachments

Related

Patches: #428

Discussion

  • Philipp Klaus Krause

    The issue in handling of Z80N / SM83 swap is fixed in [r12680].

     
    • bbbbbr

      bbbbbr - 2021-10-28

      Great, thank you!

       
  • Sebastian Riedel

    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 isDebug and such.

          if (pl->line &&
              !pl->isComment &&
              !pl->isLabel &&
              !pl->isDebug)
    
     
  • Sebastian Riedel

    Fixed in [r13187]

     

    Related

    Commit: [r13187]

    • bbbbbr

      bbbbbr - 2022-03-10

      Thanks!

       
  • Sebastian Riedel

    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB