From patchwork Thu Mar 31 16:47:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: go patch committed: Taking slice of array moves it to heap Date: Thu, 31 Mar 2011 06:47:22 -0000 From: Ian Taylor X-Patchwork-Id: 89099 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com This patch to the Go frontend fixes a bug: if you take a slice of an array, you are in effect taking the address of the array, which in Go requires moving the array to the heap. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r b9df7566fd57 go/expressions.cc --- a/go/expressions.cc Thu Mar 31 09:10:10 2011 -0700 +++ b/go/expressions.cc Thu Mar 31 09:44:18 2011 -0700 @@ -9283,10 +9283,13 @@ // A slice of an array requires an addressable array. A slice of a // slice is always possible. - if (this->end_ != NULL - && !array_type->is_open_array_type() - && !this->array_->is_addressable()) - this->report_error(_("array is not addressable")); + if (this->end_ != NULL && !array_type->is_open_array_type()) + { + if (!this->array_->is_addressable()) + this->report_error(_("array is not addressable")); + else + this->array_->address_taken(true); + } } // Return whether this expression is addressable.