Treat constant expressions cast to char as promoting to int, not unsigned int.

The following program demonstrates the problem:

#include <stdio.h>
int main(void) {
    long l = (char)1 - (char)5;
    printf("%li\n", l);  /* should print -4 */
}
This commit is contained in:
Stephen Heumann 2018-09-05 12:49:02 -05:00
parent cb0497687e
commit b2785dfe0e

View File

@ -1278,12 +1278,16 @@ var
ival := ival | $FF00;
end; {with}
end {if}
else if baseType in [cgUByte,cgUWord] then begin
else if baseType = cgUWord then begin
op^.token.kind := uintConst;
op^.token.class := intConstant;
op^.token.ival := long(op1).lsw;
if baseType = cgUByte then
op^.token.ival := op^.token.ival & $00FF;
end {else if}
else if baseType = cgUByte then begin
op^.token.kind := intConst;
op^.token.class := intConstant;
op^.token.ival := long(op1).lsw;
op^.token.ival := op^.token.ival & $00FF;
end {else if}
else if baseType = cgLong then begin
op^.token.kind := longConst;