#233 -sizeof() generates incorrect code

closed-fixed
Johan Knol
5
2013-05-25
2001-11-21
Alex Karahalios
No

The following program generates incorrect code for -sizeof(x):

extern f(int);
main() {
char x[129]; // Must be 129..255 to fail
f(-sizeof(x));
}

This is the code generated:

; main.c 4
; genCall
; Peephole 182 used 16 bit load of dptr
mov dptr,#(((0x00)<<8) + 0x7F)
lcall _f

The number should be negative, but as you can see a 0 is placed in the upper byte.

-sizeof() fails for structures/arrays in the range of 129 to 255.

The current workaround is to cast the expression to an int:

f(-(int)sizeof(x));

Alex Karahalios

Discussion

  • Johan Knol
    Johan Knol
    2001-11-25

    • milestone: --> fixed
    • assigned_to: nobody --> johanknol
    • status: open --> closed-fixed