From patchwork Tue Dec 14 23:34:16 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: 75585 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 40D1DB6EF2 for ; Wed, 15 Dec 2010 10:34:32 +1100 (EST) Received: (qmail 25532 invoked by alias); 14 Dec 2010 23:34:29 -0000 Received: (qmail 25401 invoked by uid 22791); 14 Dec 2010 23:34:28 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, 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.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 23:34:23 +0000 Received: from hpaq7.eem.corp.google.com (hpaq7.eem.corp.google.com [172.25.149.7]) by smtp-out.google.com with ESMTP id oBENYL5b027461 for ; Tue, 14 Dec 2010 15:34:21 -0800 Received: from pvc21 (pvc21.prod.google.com [10.241.209.149]) by hpaq7.eem.corp.google.com with ESMTP id oBENYJh6023600 for ; Tue, 14 Dec 2010 15:34:19 -0800 Received: by pvc21 with SMTP id 21so211907pvc.3 for ; Tue, 14 Dec 2010 15:34:19 -0800 (PST) Received: by 10.142.161.19 with SMTP id j19mr4982445wfe.440.1292369658916; Tue, 14 Dec 2010 15:34:18 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-182.mtv.corp.google.com [172.22.122.182]) by mx.google.com with ESMTPS id x18sm729914wfa.11.2010.12.14.15.34.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Dec 2010 15:34:18 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't build expressions with invalid types Date: Tue, 14 Dec 2010 15:34:16 -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 building expressions with invalid types. The specific case which failed involved a reference from a function literal to a parameter in the enclosing function with an invalid type. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 50dfff9fe261 go/expressions.cc --- a/go/expressions.cc Tue Dec 14 15:08:39 2010 -0800 +++ b/go/expressions.cc Tue Dec 14 15:32:23 2010 -0800 @@ -3824,29 +3824,28 @@ void Unary_expression::do_check_types(Gogo*) { + Type* type = this->expr_->type(); + if (type->is_error_type()) + { + this->set_is_error(); + return; + } + switch (this->op_) { case OPERATOR_PLUS: case OPERATOR_MINUS: - { - Type* type = this->expr_->type(); - if (type->integer_type() == NULL - && type->float_type() == NULL - && type->complex_type() == NULL - && !type->is_error_type()) - this->report_error(_("expected numeric type")); - } + if (type->integer_type() == NULL + && type->float_type() == NULL + && type->complex_type() == NULL) + this->report_error(_("expected numeric type")); break; case OPERATOR_NOT: case OPERATOR_XOR: - { - Type* type = this->expr_->type(); - if (type->integer_type() == NULL - && !type->is_boolean_type() - && !type->is_error_type()) - this->report_error(_("expected integer or boolean type")); - } + if (type->integer_type() == NULL + && !type->is_boolean_type()) + this->report_error(_("expected integer or boolean type")); break; case OPERATOR_AND: @@ -3858,12 +3857,8 @@ case OPERATOR_MULT: // Indirecting through a pointer. - { - Type* type = this->expr_->type(); - if (type->points_to() == NULL - && !type->is_error_type()) - this->report_error(_("expected pointer")); - } + if (type->points_to() == NULL) + this->report_error(_("expected pointer")); break; default: @@ -5474,7 +5469,10 @@ Type* left_type = this->left_->type(); Type* right_type = this->right_->type(); if (left_type->is_error_type() || right_type->is_error_type()) - return; + { + this->set_is_error(); + return; + } if (this->op_ == OPERATOR_EQEQ || this->op_ == OPERATOR_NOTEQ