From patchwork Wed Dec 15 23:40:31 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: 75703 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 E32211007D6 for ; Thu, 16 Dec 2010 10:40:45 +1100 (EST) Received: (qmail 24572 invoked by alias); 15 Dec 2010 23:40:43 -0000 Received: (qmail 24563 invoked by uid 22791); 15 Dec 2010 23:40:42 -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; Wed, 15 Dec 2010 23:40:38 +0000 Received: from kpbe12.cbf.corp.google.com (kpbe12.cbf.corp.google.com [172.25.105.76]) by smtp-out.google.com with ESMTP id oBFNeZcF026931 for ; Wed, 15 Dec 2010 15:40:35 -0800 Received: from gyf1 (gyf1.prod.google.com [10.243.50.65]) by kpbe12.cbf.corp.google.com with ESMTP id oBFNeXsx003504 for ; Wed, 15 Dec 2010 15:40:33 -0800 Received: by gyf1 with SMTP id 1so1719602gyf.7 for ; Wed, 15 Dec 2010 15:40:33 -0800 (PST) Received: by 10.236.108.33 with SMTP id p21mr2974745yhg.79.1292456433390; Wed, 15 Dec 2010 15:40:33 -0800 (PST) Received: from coign.google.com (dhcp-172-22-127-241.mtv.corp.google.com [172.22.127.241]) by mx.google.com with ESMTPS id l4sm1050530yhl.21.2010.12.15.15.40.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 15 Dec 2010 15:40:33 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash on empty struct due to recursive ref Date: Wed, 15 Dec 2010 15:40:31 -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 When there is a recursive reference to a struct, such as via a pointer, the Go frontend will build a RECORD_TYPE node and then fill it in later. Sometimes it turns out that the struct has an error, and later never comes. This patch avoids a crash for that case when referencing a field in such a struct. Bootstrapped and tested on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 2e4bc89f0e29 go/expressions.cc --- a/go/expressions.cc Wed Dec 15 14:40:54 2010 -0800 +++ b/go/expressions.cc Wed Dec 15 15:34:46 2010 -0800 @@ -9628,7 +9628,13 @@ return error_mark_node; gcc_assert(TREE_CODE(TREE_TYPE(struct_tree)) == RECORD_TYPE); tree field = TYPE_FIELDS(TREE_TYPE(struct_tree)); - gcc_assert(field != NULL_TREE); + if (field == NULL_TREE) + { + // This can happen for a type which refers to itself indirectly + // and then turns out to be erroneous. + gcc_assert(saw_errors()); + return error_mark_node; + } for (unsigned int i = this->field_index_; i > 0; --i) { field = DECL_CHAIN(field);