From patchwork Thu Dec 6 16:07:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 204286 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 337712C0277 for ; Fri, 7 Dec 2012 03:07:25 +1100 (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=1355414846; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=ypDZrhG 5iD4PXsXdYrWaWq5Yjqw=; b=vMg24lhEw8QeYNExOwzwj9pp/ng9QMjAPvg6zkm 7bIDV36yMnr+xushXebCLWg8ZIeNskb5otjLn3wvHjkfhJEHQpHgrZFVtQDJXBMB TuEVc67+DwaIQVYin5TiGA5Go0pkDieDcfE5sbO+LyQvfgf48jKJu5gxntjxqL75 pCYo= 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:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=v7C9bO/qG4rcpdgmH7+WuonT9z1dfdef5rHZNlHgr3M85H6hNBa5CMWwl+mFrg lDXxeWXwUH2nS/4fIEphzrC1YCZ3oO4a4xPwUqHmwrOBJ0v2HEuLWr1CYoDBhtJ3 aWTIrtRfY0bQCmcKjQti5ZNMCo9kXo6DgR7BHPTWi3NEI=; Received: (qmail 13380 invoked by alias); 6 Dec 2012 16:07:16 -0000 Received: (qmail 13196 invoked by uid 22791); 6 Dec 2012 16:07:15 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Thu, 06 Dec 2012 16:07:08 +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 qB6G78SR017503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Dec 2012 11:07:08 -0500 Received: from [10.3.113.18] ([10.3.113.18]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB6G777b021764; Thu, 6 Dec 2012 11:07:07 -0500 Message-ID: <50C0C2AA.9040308@redhat.com> Date: Thu, 06 Dec 2012 11:07:06 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Jakub Jelinek CC: gcc-patches List Subject: RFA: PATCH to build_array_type_1 for c++/55032 (array template argument) 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 In this PR, strip_typedefs rebuilds an array type without any typedefs and then gets confused when the rebuilt type has a different TYPE_ALIGN than the typedef-using type. This happens because the rebuilt type was found in the type_hash_canon hash table, and was originally built before the element type was complete, so the rebuilt type hasn't been laid out yet. Since we already do layout_type in build_array_type_1, it seems appropriate that it should always return a laid out type, so this patch causes us to repeat the layout if we found the type already in the hash table. Tested x86_64-pc-linux-gnu. OK for 4.7 and 4.8? commit 429af9226fcba2450a8fbfcfba85801a38d0d129 Author: Jason Merrill Date: Thu Dec 6 10:21:25 2012 -0500 PR c++/55032 * tree.c (build_array_type_1): Re-layout if we found it in the hash table. diff --git a/gcc/tree.c b/gcc/tree.c index 7cacb2a..429db49 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7505,7 +7505,12 @@ build_array_type_1 (tree elt_type, tree index_type, bool shared) hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0); if (index_type) hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); + tree old_t = t; t = type_hash_canon (hashcode, t); + if (t != old_t) + /* Lay it out again in case the element type has been completed since + the array was added to the hash table. */ + layout_type (t); } if (TYPE_CANONICAL (t) == t) diff --git a/gcc/testsuite/g++.dg/template/array24.C b/gcc/testsuite/g++.dg/template/array24.C new file mode 100644 index 0000000..07879d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array24.C @@ -0,0 +1,22 @@ +// PR c++/55032 + +template +struct vec3t { + T c[3]; +}; + +typedef vec3t vec3; + +class Bounds { + public: + Bounds(const vec3 bb[2]); + void foo(const vec3 & v) { v.c[0]; } +}; + +template +void work(T& value); + +void foo() { + vec3 bb[2]; + work(bb); +}