From afe3e9586b9040e3a8a0d8e6270f9522bea3c10e Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 12 Jul 2017 23:39:02 -0500 Subject: [PATCH] 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)++; } --- Expression.pas | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Expression.pas b/Expression.pas index 0a9fc45..1a11bcf 100644 --- a/Expression.pas +++ b/Expression.pas @@ -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 {,}