Go patch committed: do not propagate address-taken of slice element to slice

Message ID CAOyqgcXSNrU-Gd5YMEDew-jvBw-eBiSVhvDAs8Ytsbj=n=yH4g@mail.gmail.com
State New
Headers show
  • Go patch committed: do not propagate address-taken of slice element to slice
Related show

Commit Message

Ian Lance Taylor Dec. 22, 2017, 4:43 p.m.
This patch by Cherry Zhang fixes the Go frontend to 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.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.



Index: gcc/go/gofrontend/MERGE
--- gcc/go/gofrontend/MERGE	(revision 255976)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
--- gcc/go/gofrontend/expressions.cc	(revision 255976)
+++ gcc/go/gofrontend/expressions.cc	(working copy)
@@ -10871,6 +10871,14 @@  Array_index_expression::do_is_addressabl
   return this->array_->is_addressable();
+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.
Index: gcc/go/gofrontend/expressions.h
--- gcc/go/gofrontend/expressions.h	(revision 255976)
+++ gcc/go/gofrontend/expressions.h	(working copy)
@@ -2896,8 +2896,7 @@  class Array_index_expression : public Ex
   do_is_addressable() const;
-  do_address_taken(bool escapes)
-  { this->array_->address_taken(escapes); }
+  do_address_taken(bool escapes);