Menu

#2617 signed comparison implemented as unsigned comparison by compiler leading to incorrect code

closed-fixed
None
Z80
5
2017-09-25
2017-05-17
alvin
No

sdcc -v
9916 MINGW64

signed char enemygravity[]={0,0,0,0};

void doenemyverticalmovement(unsigned char a)
{
    if(enemygravity[a]<16)enemygravity[a]+=1; 
}

sdcc -mz80 -S test.c

Resulting code:

_doenemyverticalmovement::
;zzz.c:5: if(enemygravity[a]<16)enemygravity[a]+=1; 
    ld  a, #<(_enemygravity)
    ld  hl, #2
    add hl, sp
    add a, (hl)
    ld  c, a
    ld  a, #>(_enemygravity)
    adc a, #0x00
    ld  b, a
    ld  a, (bc)
    cp  a, #0x10
    ret NC
    inc a
    ld  (bc), a
    ret

The comparison against 16 is made with the single "cp a,#0x10" instruction which is an unsigned comparison. enemygravity[] is an array of signed char so this should be a signed comparison.

Discussion

  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Fixed in revision [r9917].

    Philipp

     
  • alvin

    alvin - 2017-05-18

    This one is now fixed too. Philip have you had a chance to run the tests yet on the current sdcc for the z80? I've moved on to testing more compiles and it seems there are more errors there.

     
    • Philipp Klaus Krause

      SDCC regression testing is done automatically each night on varioushost systems.
      At
      https://sourceforge.net/p/sdcc/bugs/2617/
      click the green (not tests failed) or red (something failed) dot to see details.

      Philipp

       
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     

Log in to post a comment.