From patchwork Wed Dec 15 06:16:37 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: 75607 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 062561007D1 for ; Wed, 15 Dec 2010 17:16:59 +1100 (EST) Received: (qmail 32086 invoked by alias); 15 Dec 2010 06:16:55 -0000 Received: (qmail 32077 invoked by uid 22791); 15 Dec 2010 06:16:54 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_FN, 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; Wed, 15 Dec 2010 06:16:45 +0000 Received: from hpaq2.eem.corp.google.com (hpaq2.eem.corp.google.com [172.25.149.2]) by smtp-out.google.com with ESMTP id oBF6Ggcx003824 for ; Tue, 14 Dec 2010 22:16:43 -0800 Received: from iyj18 (iyj18.prod.google.com [10.241.51.82]) by hpaq2.eem.corp.google.com with ESMTP id oBF6Ge8B029497 for ; Tue, 14 Dec 2010 22:16:41 -0800 Received: by iyj18 with SMTP id 18so906028iyj.40 for ; Tue, 14 Dec 2010 22:16:40 -0800 (PST) Received: by 10.231.11.71 with SMTP id s7mr4425048ibs.86.1292393800666; Tue, 14 Dec 2010 22:16:40 -0800 (PST) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id gy41sm653677ibb.11.2010.12.14.22.16.38 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Dec 2010 22:16:40 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash on undefined anonymous field Date: Tue, 14 Dec 2010 22:16:37 -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 fixes the Go frontend to not crash when a struct uses an anonymous field whose type is never defined. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 44d82240e42d go/types.cc --- a/go/types.cc Tue Dec 14 17:44:29 2010 -0800 +++ b/go/types.cc Tue Dec 14 22:13:21 2010 -0800 @@ -3375,6 +3375,7 @@ Struct_field_list* fields = this->fields_; if (fields == NULL) return true; + bool ret = true; for (Struct_field_list::iterator p = fields->begin(); p != fields->end(); ++p) @@ -3384,7 +3385,7 @@ { error_at(p->location(), "struct field type is incomplete"); p->set_type(Type::make_error_type()); - return false; + ret = false; } else if (p->is_anonymous()) { @@ -3396,7 +3397,7 @@ } } } - return true; + return ret; } // Whether this contains a pointer. @@ -3758,13 +3759,16 @@ bool any_fields_set = false; VEC(constructor_elt,gc)* init = VEC_alloc(constructor_elt, gc, this->fields_->size()); - Struct_field_list::const_iterator p = this->fields_->begin(); - for (tree field = TYPE_FIELDS(type_tree); - field != NULL_TREE; - field = DECL_CHAIN(field), ++p) - { - gcc_assert(p != this->fields_->end()); + + tree field = TYPE_FIELDS(type_tree); + for (Struct_field_list::const_iterator p = this->fields_->begin(); + p != this->fields_->end(); + ++p, field = DECL_CHAIN(field)) + { tree value = p->type()->get_init_tree(gogo, is_clear); + if (value == error_mark_node) + return error_mark_node; + gcc_assert(field != NULL_TREE); if (value != NULL) { constructor_elt* elt = VEC_quick_push(constructor_elt, init, NULL); @@ -3775,7 +3779,7 @@ is_constant = false; } } - gcc_assert(p == this->fields_->end()); + gcc_assert(field == NULL_TREE); if (!any_fields_set) { @@ -6891,7 +6895,9 @@ return this->named_tree_; t = make_node(RECORD_TYPE); this->named_tree_ = t; - this->type_->struct_type()->fill_in_tree(gogo, t); + t = this->type_->struct_type()->fill_in_tree(gogo, t); + if (t == error_mark_node) + return error_mark_node; break; case TYPE_ARRAY: @@ -7728,6 +7734,9 @@ if (!pf->is_anonymous()) continue; + if (pf->type()->is_error_type() || pf->type()->is_undefined()) + continue; + Named_type* fnt = pf->type()->deref()->named_type(); gcc_assert(fnt != NULL); @@ -7845,7 +7854,8 @@ pf != fields->end(); ++pf) { - if (pf->is_anonymous()) + if (pf->is_anonymous() + && (!pf->type()->is_error_type() && !pf->type()->is_undefined())) { Named_type* subtype = pf->type()->deref()->named_type(); gcc_assert(subtype != NULL);