From patchwork Wed Dec 22 06:27:52 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: 76364 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 DBF43B7093 for ; Wed, 22 Dec 2010 17:28:11 +1100 (EST) Received: (qmail 23611 invoked by alias); 22 Dec 2010 06:28:09 -0000 Received: (qmail 23603 invoked by uid 22791); 22 Dec 2010 06:28:08 -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; Wed, 22 Dec 2010 06:28:02 +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 oBM6S07t011776 for ; Tue, 21 Dec 2010 22:28:00 -0800 Received: from pvc22 (pvc22.prod.google.com [10.241.209.150]) by hpaq2.eem.corp.google.com with ESMTP id oBM6Rwjt003609 for ; Tue, 21 Dec 2010 22:27:59 -0800 Received: by pvc22 with SMTP id 22so1162293pvc.27 for ; Tue, 21 Dec 2010 22:27:58 -0800 (PST) Received: by 10.142.224.3 with SMTP id w3mr5356720wfg.23.1292999278124; Tue, 21 Dec 2010 22:27:58 -0800 (PST) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id y42sm8659970wfd.10.2010.12.21.22.27.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 21 Dec 2010 22:27:57 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't crash if constant refers to itself Date: Tue, 21 Dec 2010 22:27:52 -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 another case in the Go frontend where a constant refers to itself. If we need the type of a constant while it is being lowered, then we have an invalid recursive reference. This patch detects that case rather than crashing by trying to get the type of the initializer which has not yet been lowered. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r f22ca4fe9909 go/expressions.cc --- a/go/expressions.cc Tue Dec 21 22:17:16 2010 -0800 +++ b/go/expressions.cc Tue Dec 21 22:24:46 2010 -0800 @@ -2528,7 +2528,9 @@ if (this->type_ != NULL) return this->type_; - if (this->seen_) + Named_constant* nc = this->constant_->const_value(); + + if (this->seen_ || nc->lowering()) { this->report_error(_("constant refers to itself")); this->type_ = Type::make_error_type(); @@ -2537,7 +2539,6 @@ this->seen_ = true; - Named_constant* nc = this->constant_->const_value(); Type* ret = nc->type(); if (ret != NULL) diff -r f22ca4fe9909 go/gogo.cc --- a/go/gogo.cc Tue Dec 21 22:17:16 2010 -0800 +++ b/go/gogo.cc Tue Dec 21 22:24:46 2010 -0800 @@ -1163,8 +1163,8 @@ { Named_constant* nc = no->const_value(); - // We can recursively a constant if the initializer expression - // manages to refer to itself. + // Don't get into trouble if the constant's initializer expression + // refers to the constant itself. if (nc->lowering()) return TRAVERSE_CONTINUE; nc->set_lowering();