From patchwork Thu Dec 16 01:26:46 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: 75712 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 672F11007D6 for ; Thu, 16 Dec 2010 12:27:04 +1100 (EST) Received: (qmail 27240 invoked by alias); 16 Dec 2010 01:27:03 -0000 Received: (qmail 27232 invoked by uid 22791); 16 Dec 2010 01:27:02 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_PL, 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) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Dec 2010 01:26:56 +0000 Received: from kpbe20.cbf.corp.google.com (kpbe20.cbf.corp.google.com [172.25.105.84]) by smtp-out.google.com with ESMTP id oBG1Qr1O017121 for ; Wed, 15 Dec 2010 17:26:53 -0800 Received: from gyg4 (gyg4.prod.google.com [10.243.50.132]) by kpbe20.cbf.corp.google.com with ESMTP id oBG1Qqtd013906 for ; Wed, 15 Dec 2010 17:26:52 -0800 Received: by gyg4 with SMTP id 4so1425618gyg.8 for ; Wed, 15 Dec 2010 17:26:52 -0800 (PST) Received: by 10.236.103.12 with SMTP id e12mr779394yhg.28.1292462811959; Wed, 15 Dec 2010 17:26:51 -0800 (PST) Received: from coign.google.com ([67.218.104.35]) by mx.google.com with ESMTPS id i60sm1115420yhj.17.2010.12.15.17.26.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 15 Dec 2010 17:26:51 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash on invalid tuple assignment Date: Wed, 15 Dec 2010 17:26:46 -0800 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 to the Go frontend avoids a crash on an invalid tuple assignment. Bootstrapped and tested on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 2d785fe6afc9 go/expressions.cc --- a/go/expressions.cc Wed Dec 15 16:42:28 2010 -0800 +++ b/go/expressions.cc Wed Dec 15 17:15:16 2010 -0800 @@ -8655,6 +8655,9 @@ Type* Call_result_expression::do_type() { + if (this->classification() == EXPRESSION_ERROR) + return Type::make_error_type(); + // THIS->CALL_ can be replaced with a temporary reference due to // Call_expression::do_must_eval_in_order when there is an error. Call_expression* ce = this->call_->call_expression(); @@ -8668,34 +8671,25 @@ for (unsigned int i = 0; i < this->index_; ++i) { if (pr == results->end()) - return Type::make_error_type(); + break; ++pr; } if (pr == results->end()) - return Type::make_error_type(); + { + this->report_error(_("number of results does not match " + "number of values")); + return Type::make_error_type(); + } return pr->type(); } -// Check the type. This is where we give an error if we're trying to -// extract too many values from a call. +// Check the type. Just make sure that we trigger the warning in +// do_type. void Call_result_expression::do_check_types(Gogo*) { - bool ok = true; - Call_expression* ce = this->call_->call_expression(); - if (ce != NULL) - ok = this->index_ < ce->result_count(); - else - { - // This can happen when the call returns a single value but we - // are asking for the second result. - if (this->call_->is_error_expression()) - return; - ok = false; - } - if (!ok) - this->report_error(_("number of results does not match number of values")); + this->type(); } // Determine the type. We have nothing to do here, but the 0 result diff -r 2d785fe6afc9 go/statements.cc --- a/go/statements.cc Wed Dec 15 16:42:28 2010 -0800 +++ b/go/statements.cc Wed Dec 15 17:15:16 2010 -0800 @@ -782,6 +782,12 @@ { gcc_assert(prhs != this->rhs_->end()); + if ((*plhs)->is_error_expression() + || (*plhs)->type()->is_error_type() + || (*prhs)->is_error_expression() + || (*prhs)->type()->is_error_type()) + continue; + if ((*plhs)->is_sink_expression()) { b->add_statement(Statement::make_statement(*prhs)); @@ -802,6 +808,12 @@ plhs != this->lhs_->end(); ++plhs, ++prhs) { + if ((*plhs)->is_error_expression() + || (*plhs)->type()->is_error_type() + || (*prhs)->is_error_expression() + || (*prhs)->type()->is_error_type()) + continue; + if ((*plhs)->is_sink_expression()) continue;