From patchwork Tue Dec 14 19:36:02 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: 75527 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 3788CB6F07 for ; Wed, 15 Dec 2010 06:36:21 +1100 (EST) Received: (qmail 19243 invoked by alias); 14 Dec 2010 19:36:16 -0000 Received: (qmail 19131 invoked by uid 22791); 14 Dec 2010 19:36:14 -0000 X-SWARE-Spam-Status: No, hits=-2.3 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 19:36:07 +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 oBEJa5Ug032605 for ; Tue, 14 Dec 2010 11:36:06 -0800 Received: from gwj20 (gwj20.prod.google.com [10.200.10.20]) by kpbe20.cbf.corp.google.com with ESMTP id oBEJZJsq016360 for ; Tue, 14 Dec 2010 11:36:04 -0800 Received: by gwj20 with SMTP id 20so744895gwj.22 for ; Tue, 14 Dec 2010 11:36:04 -0800 (PST) Received: by 10.42.239.2 with SMTP id ku2mr4823362icb.497.1292355364600; Tue, 14 Dec 2010 11:36:04 -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 l26sm147483icl.16.2010.12.14.11.36.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Dec 2010 11:36:04 -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 receiver or parameters Date: Tue, 14 Dec 2010 11:36:02 -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 invalid function receiver or parameters. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. This is Go issue 1347. Ian diff -r 177a6b3ab2e4 go/gogo-tree.cc --- a/go/gogo-tree.cc Tue Dec 14 11:25:01 2010 -0800 +++ b/go/gogo-tree.cc Tue Dec 14 11:33:07 2010 -0800 @@ -1388,6 +1388,8 @@ tree Function::make_receiver_parm_decl(Gogo* gogo, Named_object* no, tree var_decl) { + if (var_decl == error_mark_node) + return error_mark_node; // If the function takes the address of a receiver which is passed // by value, then we will have an INDIRECT_REF here. We need to get // the real variable. @@ -1402,6 +1404,8 @@ { gcc_assert(is_in_heap); var_decl = TREE_OPERAND(var_decl, 0); + if (var_decl == error_mark_node) + return error_mark_node; gcc_assert(POINTER_TYPE_P(TREE_TYPE(var_decl))); val_type = TREE_TYPE(TREE_TYPE(var_decl)); } @@ -1460,9 +1464,14 @@ tree Function::copy_parm_to_heap(Gogo* gogo, Named_object* no, tree ref) { + if (ref == error_mark_node) + return error_mark_node; + gcc_assert(TREE_CODE(ref) == INDIRECT_REF); tree var_decl = TREE_OPERAND(ref, 0); + if (var_decl == error_mark_node) + return error_mark_node; gcc_assert(TREE_CODE(var_decl) == VAR_DECL); source_location loc = DECL_SOURCE_LOCATION(var_decl); @@ -1523,9 +1532,12 @@ tree var = *pp; if (TREE_CODE(var) == INDIRECT_REF) var = TREE_OPERAND(var, 0); - gcc_assert(TREE_CODE(var) == VAR_DECL); - DECL_CHAIN(var) = declare_vars; - declare_vars = var; + if (var != error_mark_node) + { + gcc_assert(TREE_CODE(var) == VAR_DECL); + DECL_CHAIN(var) = declare_vars; + declare_vars = var; + } *pp = parm_decl; } else if ((*p)->var_value()->is_in_heap()) @@ -1533,11 +1545,17 @@ // If we take the address of a parameter, then we need // to copy it into the heap. tree parm_decl = this->copy_parm_to_heap(gogo, *p, *pp); - gcc_assert(TREE_CODE(*pp) == INDIRECT_REF); - tree var_decl = TREE_OPERAND(*pp, 0); - gcc_assert(TREE_CODE(var_decl) == VAR_DECL); - DECL_CHAIN(var_decl) = declare_vars; - declare_vars = var_decl; + if (*pp != error_mark_node) + { + gcc_assert(TREE_CODE(*pp) == INDIRECT_REF); + tree var_decl = TREE_OPERAND(*pp, 0); + if (var_decl != error_mark_node) + { + gcc_assert(TREE_CODE(var_decl) == VAR_DECL); + DECL_CHAIN(var_decl) = declare_vars; + declare_vars = var_decl; + } + } *pp = parm_decl; }