From 67a29304a7baeb2026271273795be128752a6018 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 20 Nov 2016 19:25:26 -0600 Subject: [PATCH] Fix to consistently update expressionType to reflect the application of usual unary conversions (promotions). This is necessary so that subsequent processing sees the correct expression type and proceeds accordingly. In particular, without this patch, the casts in the below program were erroneously ignored: #include int main(void) { unsigned int u; unsigned char c; c = 0; u = (unsigned char)~c; printf("%u\n", u); c = 200; printf("%i\n", (unsigned char)(c+c)); } --- Expression.pas | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Expression.pas b/Expression.pas index 86daef9..b7d0977 100644 --- a/Expression.pas +++ b/Expression.pas @@ -378,8 +378,13 @@ if (lType^.kind = scalarType) and (rType^.kind = scalarType) then begin expressionType := uWordPtr; end; {else} end {if} - else {types are the same} + else begin {types are the same} UsualBinaryConversions := lt; + if lt = cgWord then {update types that may have changed} + expressionType := wordPtr + else if lt = cgExtended then + expressionType := extendedPtr; + end; {else} end {if} else Error(66); @@ -401,12 +406,18 @@ function UsualUnaryConversions{: baseTypeEnum}; { expressionType - set to result type } var - lt,rt: baseTypeEnum; {work variables} + et: baseTypeEnum; {work variables} begin {UsualUnaryConversions} UsualUnaryConversions := cgULong; -if expressionType^.kind = scalarType then - UsualUnaryConversions := Unary(expressionType^.baseType) +if expressionType^.kind = scalarType then begin + et := Unary(expressionType^.baseType); + UsualUnaryConversions := et; + if et = cgWord then {update types that may have changed} + expressionType := wordPtr + else if et = cgExtended then + expressionType := extendedPtr; + end {if} {else if expressionType^.kind in [arrayType,pointerType] then UsualUnaryConversions := cgULong}; end; {UsualUnaryConversions}