From patchwork Tue Jul 17 21:33:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 171564 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 8C2D42C00AA for ; Wed, 18 Jul 2012 07:34:14 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343165654; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=vwBIyri Z70h5K4T9yfBzLdotySI=; b=Qtj4ptSyCtc1nAGfk+RkHNb20MWAiCJIcW/Ag6L T4ZyVQUnAVlUjMxtz3kOfOMj8trJiMK5B5oQ/BHFVcD01W5lCha1G8QQtWhhHDdZ 9KZv3VjmYWFPtbqo8iTWbdqo1u0Yy/3/FYMxIL4Gb6mOU9CMT22CblaiSrP9WoUE 8igs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=lMqKrtdA/SpRro5JgtaX3e/KOZRyKoagSSr1r0iLuWKmJpwHW5np0XEPD7tT9I smL3Mh6t4jkuyuyUXaEooWRMA55hZFEHnEunCcvR2jKpamP/Ub+OT0qiI37GgdXi Gg7/upKvtFdLGOxYqwpq3VaXukhkpTtLr5Kj0Ru/hmJjg=; Received: (qmail 4099 invoked by alias); 17 Jul 2012 21:34:08 -0000 Received: (qmail 4012 invoked by uid 22791); 17 Jul 2012 21:34:07 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Jul 2012 21:33:52 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6HLXqbb025522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Jul 2012 17:33:52 -0400 Received: from [10.3.113.11] ([10.3.113.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6HLXpM6025445 for ; Tue, 17 Jul 2012 17:33:52 -0400 Message-ID: <5005DA3A.5050303@redhat.com> Date: Tue, 17 Jul 2012 17:33:46 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/53989 (ICE with array of typedef) 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 As it turns out, the problem in this case was that we were building up a canonical array as part of building up an array of the typedef, but we didn't add it to the list of array variants, so complete_vars/finalize_type_size couldn't find it to fix it up. Fixed by adding it to the variant list appropriately. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 465cefa1e575ccedfa6655018a31241ba2a669c6 Author: Jason Merrill Date: Tue Jul 17 16:56:04 2012 -0400 PR c++/53989 * tree.c (build_cplus_array_type): Also add TYPE_CANONICAL to the list of variants. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 01bc483..3c7bbb132 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -803,12 +803,23 @@ build_cplus_array_type (tree elt_type, tree index_type) { tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), index_type); + tree c = TYPE_CANONICAL (t); + if (TYPE_MAIN_VARIANT (t) != m) { TYPE_MAIN_VARIANT (t) = m; TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); TYPE_NEXT_VARIANT (m) = t; } + + /* If we built a new array type for TYPE_CANONICAL, add + that to the list of variants as well. */ + if (c && c != t && TYPE_MAIN_VARIANT (c) != m) + { + TYPE_MAIN_VARIANT (c) = m; + TYPE_NEXT_VARIANT (c) = t; + TYPE_NEXT_VARIANT (m) = c; + } } /* Push these needs up so that initialization takes place diff --git a/gcc/testsuite/g++.dg/template/array23.C b/gcc/testsuite/g++.dg/template/array23.C new file mode 100644 index 0000000..6ede8b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array23.C @@ -0,0 +1,12 @@ +// PR c++/53989 + +struct Foo { + int value; + typedef Foo Foo2; + static Foo2 const foos[2]; +}; + +template void g (T); +void bar() { + g(&Foo::foos); +}