Fix bad code generation in some cases where compound assignment operators are used to update a value through a pointer.

This could occur because a temporary location might be used both in the l-value and r-value computations, but the final assignment code assumed it still had the value from the l-value computation.

The following function demonstrates this problem (*ip is not updated, and *p is trashed):

int badinc(char **p, int *ip)
{
    *ip += *(*p)++;
}
This commit is contained in:
Stephen Heumann 2017-07-12 23:39:02 -05:00
parent 5969d80e57
commit afe3e9586b

View File

@ -2967,6 +2967,7 @@ case tree^.token.kind of
doingScalar := true;
LoadScalar(id);
lType := id^.itype;
t1 := 0;
end {if}
else begin
doingScalar := false;
@ -2978,7 +2979,6 @@ case tree^.token.kind of
Gen2t(pc_str, t1, 0, cgULong);
Gen2t(pc_lod, t1, 0, cgULong);
Gen2t(pc_lod, t1, 0, cgULong);
FreeTemp(t1, cgLongSize);
lType := expressionType^.pType;
if isBitField then begin
if unsigned then
@ -3150,6 +3150,8 @@ case tree^.token.kind of
end; {else}
Gen0t(pc_bno, lType^.baseType);
end; {else}
if t1 <> 0 then
FreeTemp(t1, cgLongSize);
end; {with}
commach: begin {,}