Save the original value when doing postfix ++/-- on fp types.

The old code would add 1 and then subtract 1, which does not necessarily give the original value (e.g. if it is much less than 1).
This commit is contained in:
Stephen Heumann 2021-03-09 18:54:31 -06:00
parent db7a0a995d
commit 031af54112
2 changed files with 22 additions and 16 deletions

View File

@ -2955,9 +2955,10 @@ var
{do real or bool inc or dec}
LoadScalar(tree^.id); {load the value}
if pc_l in [pc_lli,pc_lld] then
if iType^.cType = ctBool then begin
t1 := GetTemp(cgWordSize);
Gen2t(pc_cop, t1, 0, cgWord);
if iType^.cType in [ctBool,ctFloat,ctDouble,ctLongDouble,
ctComp] then begin
t1 := GetTemp(ord(iType^.size));
Gen2t(pc_cop, t1, 0, iType^.baseType);
end; {if}
tp := baseType;
expressionType := iType;
@ -2971,11 +2972,12 @@ var
end; {case}
{correct the value for postfix ops}
if pc_l in [pc_lli,pc_lld] then
if iType^.cType = ctBool then begin
Gen0t(pc_pop, cgWord);
Gen2t(pc_lod, t1, 0, cgWord);
Gen0t(pc_bno, cgWord);
FreeTemp(t1, cgWordSize);
if iType^.cType in [ctBool,ctFloat,ctDouble,ctLongDouble,
ctComp] then begin
Gen0t(pc_pop, iType^.baseType);
Gen2t(pc_lod, t1, 0, iType^.baseType);
Gen0t(pc_bno, iType^.baseType);
FreeTemp(t1, ord(iType^.size));
end {if}
else
IncOrDec(pc_l = pc_lld);
@ -3068,9 +3070,10 @@ var
else
Gen1t(pc_ind, 0, tp);
if pc_l in [pc_lli,pc_lld] then
if expressionType^.cType = ctBool then begin
t1 := GetTemp(cgWordSize);
Gen2t(pc_cop, t1, 0, cgWord);
if expressionType^.cType in [ctBool,ctFloat,ctDouble,ctLongDouble,
ctComp] then begin
t1 := GetTemp(ord(expressionType^.size));
Gen2t(pc_cop, t1, 0, expressionType^.baseType);
end; {if}
IncOrDec(pc_l in [pc_lli,pc_lil]); {do the ++ or --}
if isBitField then {copy the value}
@ -3079,11 +3082,12 @@ var
Gen0t(pc_cpi, tp);
Gen0t(pc_bno, tp);
if pc_l in [pc_lli,pc_lld] then {correct the value for postfix ops}
if expressionType^.cType = ctBool then begin
Gen0t(pc_pop, cgWord);
Gen2t(pc_lod, t1, 0, cgWord);
Gen0t(pc_bno, cgWord);
FreeTemp(t1, cgWordSize);
if expressionType^.cType in [ctBool,ctFloat,ctDouble,ctLongDouble,
ctComp] then begin
Gen0t(pc_pop, expressionType^.baseType);
Gen2t(pc_lod, t1, 0, expressionType^.baseType);
Gen0t(pc_bno, expressionType^.baseType);
FreeTemp(t1, ord(expressionType^.size));
end {if}
else
IncOrDec(pc_l = pc_lld);

View File

@ -1186,6 +1186,8 @@ int foo(int[42]);
152. sizeof did not give the right values for certain expressions of floating-point and character types, including expressions cast to those types.
153. The postfix ++ and -- operators might not return exactly the original value when applied to floating-point variables.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.