Skip to content

Commit

Permalink
compiler: load LHS subexpressions of op= assignment only once
Browse files Browse the repository at this point in the history
Fixes golang/go#52811

Change-Id: I369415d1188a483cba81257fdfbb0e5c1a7df1c4
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405617
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
ianlancetaylor committed May 17, 2022
1 parent f5bc28a commit 9d07072
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go/statements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,16 @@ Assignment_operation_statement::do_lower(Gogo*, Named_object*,
Move_ordered_evals moe(b);
this->lhs_->traverse_subexpressions(&moe);

// We can still be left with subexpressions that have to be loaded
// even if they don't have side effects themselves, in case the RHS
// changes variables named on the LHS.
int i;
if (this->lhs_->must_eval_subexpressions_in_order(&i))
{
Move_subexpressions ms(i, b);
this->lhs_->traverse_subexpressions(&ms);
}

Expression* lval = this->lhs_->copy();

Operator op;
Expand Down

0 comments on commit 9d07072

Please sign in to comment.