mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 23:29:27 +00:00
Fix several issues with evaluation of the ++ and -- operators.
These would generally not work correctly on bit-fields, or on floating-point values that were in a structure or were accessed via a pointer. The below program is an example that would demonstrate problems: #include <stdio.h> int main(void) { struct { signed int i:7; unsigned long int j:6; _Bool b:1; double d; } s = {-10, -20, 0, 5.0}; double d = 70.0, *dp = &d; printf("%i\n", (int)s.i++); printf("%i\n", (int)s.i--); printf("%i\n", (int)++s.i); printf("%i\n", (int)--s.i); printf("%i\n", (int)s.i); printf("%i\n", (int)s.j++); printf("%i\n", (int)s.j--); printf("%i\n", (int)++s.j); printf("%i\n", (int)--s.j); printf("%i\n", (int)s.j); printf("%i\n", s.b++); printf("%i\n", s.b--); printf("%i\n", ++s.b); printf("%i\n", --s.b); printf("%i\n", s.b); printf("%f\n", s.d++); printf("%f\n", s.d--); printf("%f\n", ++s.d); printf("%f\n", --s.d); printf("%f\n", s.d); printf("%f\n", (*dp)++); printf("%f\n", (*dp)--); printf("%f\n", ++*dp); printf("%f\n", --*dp); printf("%f\n", *dp); }
This commit is contained in:
parent
acab97ae08
commit
f2a66a524a
@ -2368,10 +2368,11 @@ var
|
|||||||
|
|
||||||
begin {DoIncDec}
|
begin {DoIncDec}
|
||||||
L_Value(tree);
|
L_Value(tree);
|
||||||
with tree^.id^ do
|
|
||||||
if (tree^.token.kind = ident)
|
if (tree^.token.kind = ident)
|
||||||
and ((iType^.kind in [scalarType,pointerType])
|
and ((tree^.id^.iType^.kind in [scalarType,pointerType])
|
||||||
or ((iType^.kind = arrayType) and (storage = parameter))) then begin
|
or ((tree^.id^.iType^.kind = arrayType) and (tree^.id^.storage = parameter)))
|
||||||
|
then
|
||||||
|
with tree^.id^ do begin
|
||||||
|
|
||||||
{check for ++ or -- of a constant}
|
{check for ++ or -- of a constant}
|
||||||
if iType^.isConstant then
|
if iType^.isConstant then
|
||||||
@ -2459,7 +2460,7 @@ var
|
|||||||
otherwise: ;
|
otherwise: ;
|
||||||
end; {case}
|
end; {case}
|
||||||
expressionType := itype;
|
expressionType := itype;
|
||||||
end {if}
|
end {with}
|
||||||
else begin
|
else begin
|
||||||
|
|
||||||
{do an indirect ++ or --}
|
{do an indirect ++ or --}
|
||||||
@ -2469,14 +2470,16 @@ var
|
|||||||
else if expressionType^.kind = pointerType then
|
else if expressionType^.kind = pointerType then
|
||||||
expressionType := expressionType^.pType;
|
expressionType := expressionType^.pType;
|
||||||
if expressionType^.kind = scalarType then
|
if expressionType^.kind = scalarType then
|
||||||
if expressionType^.baseType in [cgByte,cgUByte,cgWord,cgUWord] then
|
if expressionType^.baseType in
|
||||||
|
[cgByte,cgUByte,cgWord,cgUWord,cgReal,cgDouble,cgComp,cgExtended] then
|
||||||
tp := expressionType^.baseType
|
tp := expressionType^.baseType
|
||||||
else
|
else
|
||||||
tp := UsualUnaryConversions
|
tp := UsualUnaryConversions
|
||||||
else
|
else
|
||||||
tp := UsualUnaryConversions;
|
tp := UsualUnaryConversions;
|
||||||
if (tp in [cgByte,cgUByte,cgWord,cgUword])
|
if (tp in [cgByte,cgUByte,cgWord,cgUword])
|
||||||
and (expressionType^.cType <> ctBool) then
|
and (expressionType^.cType <> ctBool)
|
||||||
|
and not isBitField then
|
||||||
Gen0t(pc_i, tp) {do indirect inc/dec}
|
Gen0t(pc_i, tp) {do indirect inc/dec}
|
||||||
else begin
|
else begin
|
||||||
t1 := GetTemp(cgLongSize);
|
t1 := GetTemp(cgLongSize);
|
||||||
@ -2484,7 +2487,15 @@ var
|
|||||||
Gen2t(pc_lod, t1, 0, cgULong);
|
Gen2t(pc_lod, t1, 0, cgULong);
|
||||||
Gen2t(pc_lod, t1, 0, cgULong);
|
Gen2t(pc_lod, t1, 0, cgULong);
|
||||||
FreeTemp(t1, cgLongSize);
|
FreeTemp(t1, cgLongSize);
|
||||||
Gen1t(pc_ind, 0, tp); {load the value}
|
{load the value}
|
||||||
|
if isBitField then begin
|
||||||
|
if unsigned then
|
||||||
|
Gen2t(pc_lbu, bitDisp, bitSize, tp)
|
||||||
|
else
|
||||||
|
Gen2t(pc_lbf, bitDisp, bitSize, tp);
|
||||||
|
end {if}
|
||||||
|
else
|
||||||
|
Gen1t(pc_ind, 0, tp);
|
||||||
if pc_l in [pc_lli,pc_lld] then
|
if pc_l in [pc_lli,pc_lld] then
|
||||||
if expressionType^.cType = ctBool then begin
|
if expressionType^.cType = ctBool then begin
|
||||||
t1 := GetTemp(cgWordSize);
|
t1 := GetTemp(cgWordSize);
|
||||||
@ -2492,18 +2503,10 @@ var
|
|||||||
end; {if}
|
end; {if}
|
||||||
IncOrDec(pc_l in [pc_lli,pc_lil]); {do the ++ or --}
|
IncOrDec(pc_l in [pc_lli,pc_lil]); {do the ++ or --}
|
||||||
if isBitField then {copy the value}
|
if isBitField then {copy the value}
|
||||||
if bitDisp+bitSize > 16 then begin
|
Gen2t(pc_cbf, bitDisp, bitSize, tp)
|
||||||
Gen2t(pc_cbf, bitDisp, bitSize, cgLong);
|
else
|
||||||
Gen0t(pc_bno, cgLong);
|
|
||||||
end {if}
|
|
||||||
else begin
|
|
||||||
Gen2t(pc_cbf, bitDisp, bitSize, cgWord);
|
|
||||||
Gen0t(pc_bno, cgWord);
|
|
||||||
end {else}
|
|
||||||
else begin
|
|
||||||
Gen0t(pc_cpi, tp);
|
Gen0t(pc_cpi, tp);
|
||||||
Gen0t(pc_bno, tp);
|
Gen0t(pc_bno, tp);
|
||||||
end; {else}
|
|
||||||
if pc_l in [pc_lli,pc_lld] then {correct the value for postfix ops}
|
if pc_l in [pc_lli,pc_lld] then {correct the value for postfix ops}
|
||||||
if expressionType^.cType = ctBool then begin
|
if expressionType^.cType = ctBool then begin
|
||||||
Gen0t(pc_pop, cgWord);
|
Gen0t(pc_pop, cgWord);
|
||||||
|
Loading…
Reference in New Issue
Block a user