From patchwork Fri Jul 20 16:10:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 172308 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 8101E2C036F for ; Sat, 21 Jul 2012 02:11:09 +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=1343405470; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=fk2k22kDIdbzer4K//i15rdal2g=; b=KcieuDsRNkZjOr2 cyLArYJE8Y48MP72iP1JyLY4DzVPDUtyTJ0wsKkM9NaqxCUuwNCP9M6pUEFTGfGY L+R+NWDWmFocpc1qwj3C9QaqCt35Q+6eE0rOF9UTLjkuQE/Wc7x4+5Vy0PVFr+nX HftIJo/BGc2IDWWag0ajzlEb83IM= 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:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ubJLVEWnxIHJSI01K0p+srAHO2dD6QSoIWFFOvEjMKF/bjaf7Z57sAEHAfjfDo Ize1qfeWhh0+0BGWGWzFy+BkBKll2Y4QMiZfIWaw10422eUG3GrrYGs/6lSU2+11 Ojdn/cN6qqZR7IDwnAUvjFiAedZolXARI5McrvuK7wfro=; Received: (qmail 19466 invoked by alias); 20 Jul 2012 16:11:03 -0000 Received: (qmail 19437 invoked by uid 22791); 20 Jul 2012 16:11:01 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, 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; Fri, 20 Jul 2012 16:10:41 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6KGAe6P002171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 Jul 2012 12:10:41 -0400 Received: from [10.3.113.11] ([10.3.113.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6KGAdqx026416; Fri, 20 Jul 2012 12:10:40 -0400 Message-ID: <500982FF.5080801@redhat.com> Date: Fri, 20 Jul 2012 12:10:39 -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: Jakub Jelinek CC: gcc-patches@gcc.gnu.org Subject: Re: [C++ PATCH] Fix a regression from build_cplus_array_type recent change (PR c++/54038) References: <20120720132634.GL4807@tucnak.redhat.com> In-Reply-To: <20120720132634.GL4807@tucnak.redhat.com> 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 On 07/20/2012 09:26 AM, Jakub Jelinek wrote: > As detailed in the PR, I believe we should only add c into m's variant chain > if m's element type is the main variant of c's element type. We want c to get onto the appropriate variant chain even if it isn't m's, so I'm applying this patch instead. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 3e16b98aa7e47f321974b5623cd68d2671a87f1e Author: Jason Merrill Date: Fri Jul 20 11:19:07 2012 -0400 PR c++/54038 * tree.c (build_cplus_array_type): Use build_cplus_array_type to build canonical array type rather than mess with its TYPE_*_VARIANT. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 1e98f85..de9e0f6 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -786,7 +786,18 @@ build_cplus_array_type (tree elt_type, tree index_type) } } else - t = build_array_type (elt_type, index_type); + { + if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type) + && !(index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) + && (TYPE_CANONICAL (elt_type) != elt_type + || (index_type && TYPE_CANONICAL (index_type) != index_type))) + /* Make sure that the canonical type is on the appropriate + variants list. */ + build_cplus_array_type + (TYPE_CANONICAL (elt_type), + index_type ? TYPE_CANONICAL (index_type) : index_type); + t = build_array_type (elt_type, index_type); + } /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the element type as well, so fix it up if needed. */ @@ -794,7 +805,6 @@ 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) { @@ -802,15 +812,6 @@ build_cplus_array_type (tree elt_type, tree index_type) 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/other/array7.C b/gcc/testsuite/g++.dg/other/array7.C new file mode 100644 index 0000000..72322f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/array7.C @@ -0,0 +1,9 @@ +// PR c++/54038 + +extern const char *const v[]; +typedef char T; +void foo (const T *const[]); +struct A +{ + static const char *const a[]; +};