#2069 Z80: Wrong code generated for structure handling

z80 port (188)

Attached example generates wrong code using command line:
sdcc -mz80 -c --max-allocs-per-node 60000 sdccerr.c
See sdcc.lst:
- lines 95, 95 - hl is populated by function parameter 'i'
- line 104 - ldir is done with bc=4, causing hl to be incremented by 4
- lines 120-126 - structure pointed by 'i' is being populated using hl, but hl points 4 bytes forward already - changed by ldir!

problem does not occur when omitting --max-allocs-per-node.

SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08 3.2.1 #8054 (Jul 25 2012) (Linux)


  • mz-fuzzy

    mz-fuzzy - 2012-08-20
  • mz-fuzzy

    mz-fuzzy - 2012-08-20
    • priority: 5 --> 7
  • mz-fuzzy

    mz-fuzzy - 2012-08-20

    increasing priority as a wrong code is generated silently.

  • Philipp Klaus Krause

    • assigned_to: nobody --> spth
    • status: open --> closed-fixed
  • Philipp Klaus Krause

    Fixed in revision #8091.

    Now hl is saved to stack and restored in such cases (and for the example given sdcc then avoids the use of hl here, not willing to pay the push/pop cost).

    Unfortunately the --max-allocs-per-node 60000 means regular regression testing will not safeguard against this bug reappearing. But I tend to run the regression tests with different --max-allocs-per-node values once in a while, so the test is better than nothing.



Log in to post a comment.