Skip to content

Commit 9d07072

Browse files
compiler: load LHS subexpressions of op= assignment only once
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]>
1 parent f5bc28a commit 9d07072

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

go/statements.cc

+10
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,16 @@ Assignment_operation_statement::do_lower(Gogo*, Named_object*,
12601260
Move_ordered_evals moe(b);
12611261
this->lhs_->traverse_subexpressions(&moe);
12621262

1263+
// We can still be left with subexpressions that have to be loaded
1264+
// even if they don't have side effects themselves, in case the RHS
1265+
// changes variables named on the LHS.
1266+
int i;
1267+
if (this->lhs_->must_eval_subexpressions_in_order(&i))
1268+
{
1269+
Move_subexpressions ms(i, b);
1270+
this->lhs_->traverse_subexpressions(&ms);
1271+
}
1272+
12631273
Expression* lval = this->lhs_->copy();
12641274

12651275
Operator op;

0 commit comments

Comments
 (0)