From patchwork Tue Dec 21 18:31:55 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: 76313 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 06DB1B7093 for ; Wed, 22 Dec 2010 05:32:18 +1100 (EST) Received: (qmail 22528 invoked by alias); 21 Dec 2010 18:32:12 -0000 Received: (qmail 22519 invoked by uid 22791); 21 Dec 2010 18:32:10 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, 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.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Dec 2010 18:32:02 +0000 Received: from hpaq11.eem.corp.google.com (hpaq11.eem.corp.google.com [172.25.149.11]) by smtp-out.google.com with ESMTP id oBLIW0P8007183 for ; Tue, 21 Dec 2010 10:32:00 -0800 Received: from pzk34 (pzk34.prod.google.com [10.243.19.162]) by hpaq11.eem.corp.google.com with ESMTP id oBLIVwiT030869 for ; Tue, 21 Dec 2010 10:31:59 -0800 Received: by pzk34 with SMTP id 34so1257553pzk.10 for ; Tue, 21 Dec 2010 10:31:58 -0800 (PST) Received: by 10.142.194.10 with SMTP id r10mr4858724wff.361.1292956317980; Tue, 21 Dec 2010 10:31:57 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-207.mtv.corp.google.com [172.22.122.207]) by mx.google.com with ESMTPS id b11sm7891708wff.9.2010.12.21.10.31.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 21 Dec 2010 10:31:57 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Report errors for temporary statements Date: Tue, 21 Dec 2010 10:31:55 -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 The Go frontend assumed that a temporary statement was always correct with respect to types. That is not the case: types are not checked before temporary statements are created (temporary statements are used to, e.g., split tuple assignments into single assignments). This patch fixes the compiler to issue an error on a bad type rather than crashing. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 7f448375b9ac go/statements.cc --- a/go/statements.cc Tue Dec 21 10:19:17 2010 -0800 +++ b/go/statements.cc Tue Dec 21 10:26:59 2010 -0800 @@ -350,7 +350,18 @@ Temporary_statement::do_check_types(Gogo*) { if (this->type_ != NULL && this->init_ != NULL) - gcc_assert(Type::are_assignable(this->type_, this->init_->type(), NULL)); + { + std::string reason; + if (!Type::are_assignable(this->type_, this->init_->type(), &reason)) + { + if (reason.empty()) + error_at(this->location(), "incompatible types in assignment"); + else + error_at(this->location(), "incompatible types in assignment (%s)", + reason.c_str()); + this->set_is_error(); + } + } } // Return a tree.