From b2785dfe0eb294f78f3ccc919c1d4ee717b305ca Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 5 Sep 2018 12:49:02 -0500 Subject: [PATCH] Treat constant expressions cast to char as promoting to int, not unsigned int. The following program demonstrates the problem: #include int main(void) { long l = (char)1 - (char)5; printf("%li\n", l); /* should print -4 */ } --- Expression.pas | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Expression.pas b/Expression.pas index 2deacb0..235b223 100644 --- a/Expression.pas +++ b/Expression.pas @@ -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;