From patchwork Fri Oct 8 20:36:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 67281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4FA0DB70E2 for ; Sat, 9 Oct 2010 07:37:11 +1100 (EST) Received: (qmail 30658 invoked by alias); 8 Oct 2010 20:37:08 -0000 Received: (qmail 30635 invoked by uid 22791); 8 Oct 2010 20:37:07 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Oct 2010 20:37:02 +0000 Received: from wpaz33.hot.corp.google.com (wpaz33.hot.corp.google.com [172.24.198.97]) by smtp-out.google.com with ESMTP id o98Kb0LR027357 for ; Fri, 8 Oct 2010 13:37:00 -0700 Received: from pwj4 (pwj4.prod.google.com [10.241.219.68]) by wpaz33.hot.corp.google.com with ESMTP id o98KZ4fa005351 for ; Fri, 8 Oct 2010 13:36:59 -0700 Received: by pwj4 with SMTP id 4so285100pwj.19 for ; Fri, 08 Oct 2010 13:36:59 -0700 (PDT) Received: by 10.115.112.39 with SMTP id p39mr180587wam.52.1286570219273; Fri, 08 Oct 2010 13:36:59 -0700 (PDT) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id d31sm3463640wam.5.2010.10.08.13.36.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 08 Oct 2010 13:36:57 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Taking slice of composite literal puts literal on heap Date: Fri, 08 Oct 2010 13:36:52 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch does two things. The first is that taking the slice of a composite literal requires putting the composite literal on the heap, so that the slice has something permanent to point to. The second is some adjustments to #includes and names for the upcoming merge with gcc mainline. Committed to gccgo branch. Ian diff -r 426520ed103c go/expressions.cc --- a/go/expressions.cc Fri Oct 08 13:31:22 2010 -0700 +++ b/go/expressions.cc Fri Oct 08 13:34:52 2010 -0700 @@ -10,12 +10,14 @@ extern "C" { +#include "toplev.h" #include "intl.h" #include "tree.h" #include "gimple.h" #include "tree-iterator.h" #include "convert.h" #include "real.h" +#include "realmpfr.h" #include "tm_p.h" } @@ -131,7 +133,7 @@ void Expression::do_discarding_value() { - this->warn_unused_value(); + this->warn_about_unused_value(); } // This virtual function is called to export expressions. This will @@ -146,7 +148,7 @@ // Warn that the value of the expression is not used. void -Expression::warn_unused_value() +Expression::warn_about_unused_value() { warning_at(this->location(), OPT_Wunused_value, "value computed is not used"); } @@ -5179,7 +5181,7 @@ if (this->op_ == OPERATOR_OROR || this->op_ == OPERATOR_ANDAND) this->right_->discarding_value(); else - this->warn_unused_value(); + this->warn_about_unused_value(); } // Get type. @@ -9003,6 +9005,13 @@ Expression::make_array_index(Expression* array, Expression* start, Expression* end, source_location location) { + // Taking a slice of a composite literal requires moving the literal + // onto the heap. + if (end != NULL && array->is_composite_literal()) + { + array = Expression::make_heap_composite(array, location); + array = Expression::make_unary(OPERATOR_MULT, array, location); + } return new Array_index_expression(array, start, end, location); } diff -r 426520ed103c go/expressions.h --- a/go/expressions.h Fri Oct 08 13:31:22 2010 -0700 +++ b/go/expressions.h Fri Oct 08 13:34:52 2010 -0700 @@ -682,7 +682,7 @@ // For children to call to warn about an unused value. void - warn_unused_value(); + warn_about_unused_value(); // For children to call when they detect that they are in error. void