From patchwork Tue Feb 15 22:37:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 83308 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 64421B70F9 for ; Wed, 16 Feb 2011 09:37:25 +1100 (EST) Received: (qmail 2798 invoked by alias); 15 Feb 2011 22:37:22 -0000 Received: (qmail 2788 invoked by uid 22791); 15 Feb 2011 22:37:21 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, 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, 15 Feb 2011 22:37:16 +0000 Received: from hpaq6.eem.corp.google.com (hpaq6.eem.corp.google.com [172.25.149.6]) by smtp-out.google.com with ESMTP id p1FMbDnm009086 for ; Tue, 15 Feb 2011 14:37:13 -0800 Received: from iwn3 (iwn3.prod.google.com [10.241.68.67]) by hpaq6.eem.corp.google.com with ESMTP id p1FMaiqR008506 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 15 Feb 2011 14:37:12 -0800 Received: by iwn3 with SMTP id 3so717825iwn.26 for ; Tue, 15 Feb 2011 14:37:12 -0800 (PST) Received: by 10.42.164.132 with SMTP id g4mr7446341icy.127.1297809432217; Tue, 15 Feb 2011 14:37:12 -0800 (PST) Received: from coign.google.com (dhcp-172-19-11-171.mtv.corp.google.com [172.19.11.171]) by mx.google.com with ESMTPS id u9sm3938969ibe.2.2011.02.15.14.37.11 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Feb 2011 14:37:11 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash on erroneous thunk call Date: Tue, 15 Feb 2011 14:37:09 -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 crashing on an erroneous thunk call. This treats the calls built for thunks more like regular calls, and runs the usual type checking pass on them. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r b511d4c035b7 go/statements.cc --- a/go/statements.cc Tue Feb 15 11:52:43 2011 -0800 +++ b/go/statements.cc Tue Feb 15 14:34:31 2011 -0800 @@ -2215,6 +2215,8 @@ Struct_field_list::const_iterator p = fields->begin(); for (unsigned int i = 0; i < next_index; ++i) ++p; + bool is_recover_call = ce->is_recover_call(); + Expression* recover_arg = NULL; for (; p != fields->end(); ++p, ++next_index) { Expression* thunk_param = Expression::make_var_reference(named_parameter, @@ -2224,19 +2226,28 @@ Expression* param = Expression::make_field_reference(thunk_param, next_index, location); - call_params->push_back(param); + if (!is_recover_call) + call_params->push_back(param); + else + { + gcc_assert(call_params->empty()); + recover_arg = param; + } + } + + if (call_params->empty()) + { + delete call_params; + call_params = NULL; } Expression* call = Expression::make_call(func_to_call, call_params, false, location); // We need to lower in case this is a builtin function. call = call->lower(gogo, function, -1); - if (may_call_recover) - { - Call_expression* ce = call->call_expression(); - if (ce != NULL) - ce->set_is_deferred(); - } + Call_expression* call_ce = call->call_expression(); + if (call_ce != NULL && may_call_recover) + call_ce->set_is_deferred(); Statement* call_statement = Statement::make_statement(call); @@ -2244,6 +2255,12 @@ // just for this statement now. call_statement->determine_types(); + // Sanity check. + call->check_types(gogo); + + if (call_ce != NULL && recover_arg != NULL) + call_ce->set_recover_arg(recover_arg); + gogo->add_statement(call_statement); // If this is a defer statement, the label comes immediately after