From patchwork Tue Dec 4 05:17:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 203559 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 627F92C0090 for ; Tue, 4 Dec 2012 16:18:28 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355203109; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=pZUqnnH ecDn2ekVPu+i5zB7N4YM=; b=NpSn6gZLHVqu4QZx8xfmS5EORuqTwFWo2zyaUJc 4DpfkFGmTkZtzJrz1h2njj5gHnVvcdCSGD3PG9NY2axce5dzehxGVDy9j/JOwxno mR3phVTw3CYmcLeROApYJ5KrMW77yOxaGg8G5ngNdbqgzC+xOFWJZdvJd3XdwCgW xrh4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rWoL7NicjsHMHR2IWBB/9gxxXUERBvdoxb8jo1HzYnPmmKlbrUR8r1avAtEGsi EBjQsiwwJPR3KTM5P7Djmj4zSXIrt7TlcuJKira0kp6fyhaMbBnDMY/qm1CGLRZx cQVhnrvAOIduIsbqyPesagVqhJFGG3V2kgqfb2T6V9moY=; Received: (qmail 7525 invoked by alias); 4 Dec 2012 05:18:12 -0000 Received: (qmail 7502 invoked by uid 22791); 4 Dec 2012 05:18:11 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pa0-f47.google.com (HELO mail-pa0-f47.google.com) (209.85.220.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 04 Dec 2012 05:18:04 +0000 Received: by mail-pa0-f47.google.com with SMTP id fa10so2215354pad.20 for ; Mon, 03 Dec 2012 21:18:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=EIn/nrDTwugWmb9T7Df6wFAPkm6x2J1Br3LWmkBlMrk=; b=c6yz+ZYKTOuhEe0IEVE+DHsDJrfClBLfUJtpzU2lBm8W+7QMMz2Ma4TxouKoBfXxmE 1h/ELxorm3ZYKqbQxMk8oxKIWYuB9nTquaZO+qQvryQaT7P6HpLyEs40Rh76Q8s0a2Bt 81roc078e9mNAEGrkc2DxIZofIfhpI5LXoVQJosrsR27A41FDjk2YkSOkYDhvAJpjq19 BKxKLmvvregvd0yakISAKOWqSMHawQlSkvlk84gDq1kbsCyBSllV1JORQkeu4hJMFqZ9 Z+QnIEti/jXvqerC6FYkAgOqTE+IaFiEIz0HzlyApi+B7+ZBLeRVBHNaRp+L1WBQAYLo i8Zw== Received: by 10.68.241.136 with SMTP id wi8mr35753983pbc.95.1354598283261; Mon, 03 Dec 2012 21:18:03 -0800 (PST) Received: from coign.google.com ([2401:fa00:0:9:224:d7ff:fe8f:f634]) by mx.google.com with ESMTPS id oi2sm347530pbb.62.2012.12.03.21.18.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 03 Dec 2012 21:18:02 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix crash on go/defer of some builtin functions Date: Mon, 03 Dec 2012 21:17:58 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkdC5dPJcC6e4/hIy/haXUwDcrFRvCJRu0+T0e/wPZWVguUh7NtO2U+i1F+q4w26VbrVdQam8TA8dgAQGDiwHl4klvYUnOcDshpYHDFiaUDoGnBvQikuy4ODOkmlAMrpEalIrV5KPzGaVwWVnxD+lD7J7JlHTm7hJezYFM7EDtuKD6KKXH5OW21lsCt3o5fB3zCTqxG 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 compiler fixes a crash when using go or defer with some builtin functions, namely those that have no side-effects. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian diff -r 952fc7825cfa go/expressions.cc --- a/go/expressions.cc Mon Dec 03 16:27:21 2012 -0800 +++ b/go/expressions.cc Mon Dec 03 20:57:51 2012 -0800 @@ -80,10 +80,11 @@ // expression is being discarded. By default, we give an error. // Expressions with side effects override. -void +bool Expression::do_discarding_value() { this->unused_value_error(); + return false; } // This virtual function is called to export expressions. This will @@ -100,7 +101,7 @@ void Expression::unused_value_error() { - error_at(this->location(), "value computed is not used"); + this->report_error(_("value computed is not used")); } // Note that this expression is an error. This is called by children @@ -786,9 +787,9 @@ return true; } - void + bool do_discarding_value() - { } + { return true; } Type* do_type() @@ -1149,9 +1150,9 @@ { } protected: - void + bool do_discarding_value() - { } + { return true; } Type* do_type(); @@ -5326,13 +5327,19 @@ // Note that the value is being discarded. -void +bool Binary_expression::do_discarding_value() { if (this->op_ == OPERATOR_OROR || this->op_ == OPERATOR_ANDAND) - this->right_->discarding_value(); - else - this->unused_value_error(); + { + this->right_->discarding_value(); + return true; + } + else + { + this->unused_value_error(); + return false; + } } // Get type. @@ -6536,7 +6543,7 @@ bool do_numeric_constant_value(Numeric_constant*) const; - void + bool do_discarding_value(); Type* @@ -7338,7 +7345,7 @@ // discarding the value of an ordinary function call, but we do for // builtin functions, purely for consistency with the gc compiler. -void +bool Builtin_call_expression::do_discarding_value() { switch (this->code_) @@ -7359,7 +7366,7 @@ case BUILTIN_OFFSETOF: case BUILTIN_SIZEOF: this->unused_value_error(); - break; + return false; case BUILTIN_CLOSE: case BUILTIN_COPY: @@ -7368,7 +7375,7 @@ case BUILTIN_PRINT: case BUILTIN_PRINTLN: case BUILTIN_RECOVER: - break; + return true; } } diff -r 952fc7825cfa go/expressions.h --- a/go/expressions.h Mon Dec 03 16:27:21 2012 -0800 +++ b/go/expressions.h Mon Dec 03 20:57:51 2012 -0800 @@ -360,10 +360,11 @@ // This is called if the value of this expression is being // discarded. This issues warnings about computed values being - // unused. - void + // unused. This returns true if all is well, false if it issued an + // error message. + bool discarding_value() - { this->do_discarding_value(); } + { return this->do_discarding_value(); } // Return whether this is an error expression. bool @@ -689,7 +690,7 @@ { return false; } // Called by the parser if the value is being discarded. - virtual void + virtual bool do_discarding_value(); // Child class holds type. @@ -1205,7 +1206,7 @@ bool do_numeric_constant_value(Numeric_constant*) const; - void + bool do_discarding_value(); Type* @@ -1373,9 +1374,9 @@ virtual Expression* do_lower(Gogo*, Named_object*, Statement_inserter*, int); - void + bool do_discarding_value() - { } + { return true; } virtual Type* do_type(); @@ -2056,9 +2057,9 @@ do_traverse(Traverse* traverse) { return Expression::traverse(&this->channel_, traverse); } - void + bool do_discarding_value() - { } + { return true; } Type* do_type(); diff -r 952fc7825cfa go/statements.cc --- a/go/statements.cc Mon Dec 03 16:27:21 2012 -0800 +++ b/go/statements.cc Mon Dec 03 20:57:51 2012 -0800 @@ -2006,6 +2006,8 @@ void Thunk_statement::do_check_types(Gogo*) { + if (!this->call_->discarding_value()) + return; Call_expression* ce = this->call_->call_expression(); if (ce == NULL) { @@ -2471,11 +2473,15 @@ Expression_statement* es = static_cast(call_statement); Call_expression* ce = es->expr()->call_expression(); - go_assert(ce != NULL); - if (may_call_recover) - ce->set_is_deferred(); - if (recover_arg != NULL) - ce->set_recover_arg(recover_arg); + if (ce == NULL) + go_assert(saw_errors()); + else + { + if (may_call_recover) + ce->set_is_deferred(); + if (recover_arg != NULL) + ce->set_recover_arg(recover_arg); + } } // That is all the thunk has to do.