diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-07-11 14:22:12 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-07-11 14:22:12 +0000 |
commit | 305130b92e1a785d89178ce6334ead38e975268f (patch) | |
tree | bda3b9e97b0fab2129706a037775832f83e6982f /gcc/go/gofrontend/expressions.cc | |
parent | 2bae8b2fadab13b6f886829f782e4d5cffdfafd6 (diff) | |
download | gcc-305130b92e1a785d89178ce6334ead38e975268f.zip gcc-305130b92e1a785d89178ce6334ead38e975268f.tar.gz gcc-305130b92e1a785d89178ce6334ead38e975268f.tar.bz2 |
compiler: fix evaluation order of LHS index expressions
The spec says that when an index expression appears on the left hand
side of an assignment, the operands should be evaluated. The
gofrontend code was assuming that that only referred to the index
operand. But discussion of https://golang.org/issue/23188 has
clarified that this means both the slice/map/string operand and the
index operand. Adjust the gofrontend code accordingly.
Fixes golang/go#23188
Reviewed-on: https://go-review.googlesource.com/123155
From-SVN: r262554
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 89b265b..e7d0b75 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -10898,6 +10898,20 @@ Array_index_expression::do_check_types(Gogo*) } } +// The subexpressions of an array index must be evaluated in order. +// If this is indexing into an array, rather than a slice, then only +// the index should be evaluated. Since this is called for values on +// the left hand side of an assigment, evaluating the array, meaning +// copying the array, will cause a different array to be modified. + +bool +Array_index_expression::do_must_eval_subexpressions_in_order( + int* skip) const +{ + *skip = this->array_->type()->is_slice_type() ? 0 : 1; + return true; +} + // Flatten array indexing by using temporary variables for slices and indexes. Expression* |