mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-08-15 07:27:27 +00:00
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 <stdio.h> 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)); }
This commit is contained in:
@@ -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}
|
||||
|
Reference in New Issue
Block a user