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
Series
  • 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.

Ian

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 255976)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -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.
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();
 }
 
+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*
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;
 
   void
-  do_address_taken(bool escapes)
-  { this->array_->address_taken(escapes); }
+  do_address_taken(bool escapes);
 
   void
   do_issue_nil_check()