diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:50:22 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:50:22 +0000 |
commit | 964c809fb28f2bbb5b7c35d7951911abff242b94 (patch) | |
tree | b28da004d38101795417db74c7864f081e38ba3f /gcc/go/gofrontend/statements.cc | |
parent | 4cff15eaca92180183608371351ba2c818990304 (diff) | |
download | gcc-964c809fb28f2bbb5b7c35d7951911abff242b94.zip gcc-964c809fb28f2bbb5b7c35d7951911abff242b94.tar.gz gcc-964c809fb28f2bbb5b7c35d7951911abff242b94.tar.bz2 |
compiler: in range, evaluate array if it has receives or calls
The last change was incomplete, in that it did not evaluate the array
argument in some cases where it had to be evaluated. This reuses the
existing code for checking whether len/cap is constant.
Also clean up the use of _ as the second variable in a for/range,
which was previously inconsistent depending on whether the statement
used = or :=.
Updates golang/go#22313
Reviewed-on: https://go-review.googlesource.com/91715
From-SVN: r257377
Diffstat (limited to 'gcc/go/gofrontend/statements.cc')
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index 0b1d722..c94d8cf 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -5311,11 +5311,12 @@ For_range_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing, // constant, then we do not evaluate the range variable. len(x) is // a contant if x is a string constant or if x is an array. If x is // a constant then evaluating it won't make any difference, so the - // only case to consider is when x is an array. + // only case to consider is when x is an array whose length is constant. bool eval = true; - if (this->value_var_ == NULL + if ((this->value_var_ == NULL || this->value_var_->is_sink_expression()) && range_type->array_type() != NULL - && !range_type->is_slice_type()) + && !range_type->is_slice_type() + && Builtin_call_expression::array_len_is_constant(this->range_)) eval = false; Location loc = this->location(); @@ -5341,7 +5342,7 @@ For_range_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing, temp_block->add_statement(index_temp); Temporary_statement* value_temp = NULL; - if (this->value_var_ != NULL) + if (this->value_var_ != NULL && !this->value_var_->is_sink_expression()) { value_temp = Statement::make_temporary(value_type, NULL, loc); temp_block->add_statement(value_temp); @@ -5393,7 +5394,7 @@ For_range_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing, Statement* assign; Expression* index_ref = Expression::make_temporary_reference(index_temp, loc); - if (this->value_var_ == NULL) + if (this->value_var_ == NULL || this->value_var_->is_sink_expression()) assign = Statement::make_assignment(this->index_var_, index_ref, loc); else { |