From d7b24d5556b2dae71e1ed3c907d33db21cd2ce72 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 22 Dec 2017 16:43:28 +0000 Subject: [PATCH] compiler: do not propagate address-taken of a slice element to the slice Array_index_expression may be used for indexing/slicing array or slice. If a slice element is address taken, the slice itself is not necessarily address taken. Only propagate address-taken for arrays. Reviewed-on: https://go-review.googlesource.com/83877 From-SVN: r255977 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/expressions.cc | 8 ++++++++ gcc/go/gofrontend/expressions.h | 3 +-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index b81922efe59..3ba34626478 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -83fc0e440b8c151edc5b1c67006257aad522ca04 +9b9bece388d1bacdc9d1d0024e722ffe449d221d The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 8ae1013a6a9..f5adc18586d 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -10871,6 +10871,14 @@ Array_index_expression::do_is_addressable() const return this->array_->is_addressable(); } +void +Array_index_expression::do_address_taken(bool escapes) +{ + // In &x[0], if x is a slice, then x's address is not taken. + if (!this->array_->type()->is_slice_type()) + this->array_->address_taken(escapes); +} + // Get the backend representation for an array index. Bexpression* diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index a4f655828a5..cb608900566 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -2896,8 +2896,7 @@ class Array_index_expression : public Expression do_is_addressable() const; void - do_address_taken(bool escapes) - { this->array_->address_taken(escapes); } + do_address_taken(bool escapes); void do_issue_nil_check() -- 2.30.2