From patchwork Mon Jun 20 14:23:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 101134 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 79318B6F7B for ; Tue, 21 Jun 2011 00:23:51 +1000 (EST) Received: (qmail 30270 invoked by alias); 20 Jun 2011 14:23:48 -0000 Received: (qmail 30253 invoked by uid 22791); 20 Jun 2011 14:23:47 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Mon, 20 Jun 2011 14:23:32 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5KENVZt003431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 20 Jun 2011 10:23:32 -0400 Received: from [127.0.0.1] ([10.3.113.2]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5KENVjm021575 for ; Mon, 20 Jun 2011 10:23:31 -0400 Message-ID: <4DFF57E3.7080407@redhat.com> Date: Mon, 20 Jun 2011 10:23:31 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48138 (losing __attribute ((aligned)) on 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 strip_typedefs needs to propagate DECL_USER_ALIGN as well as attributes in the attribute list. Tested x86_64-pc-linux-gnu, applying to trunk. commit fd43d02986ccbd7c43014ea093fe06f94d3d0af7 Author: Jason Merrill Date: Sun Jun 19 22:20:03 2011 -0400 PR c++/48138 * tree.c (strip_typedefs): Use build_aligned_type. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index c1824b4..3100508 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1167,6 +1167,16 @@ strip_typedefs (tree t) if (!result) result = TYPE_MAIN_VARIANT (t); + if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result) + || TYPE_ALIGN (t) != TYPE_ALIGN (result)) + { + gcc_assert (TYPE_USER_ALIGN (t)); + if (TYPE_ALIGN (t) == TYPE_ALIGN (result)) + result = build_variant_type_copy (result); + else + result = build_aligned_type (result, TYPE_ALIGN (t)); + TYPE_USER_ALIGN (result) = true; + } if (TYPE_ATTRIBUTES (t)) result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t)); return cp_build_qualified_type (result, cp_type_quals (t)); diff --git a/gcc/testsuite/g++.dg/ext/attr-aligned01.C b/gcc/testsuite/g++.dg/ext/attr-aligned01.C new file mode 100644 index 0000000..a051c6e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-aligned01.C @@ -0,0 +1,20 @@ +// PR c++/48138 +// { dg-options -std=c++0x } + +#define ALIGNED(x) __attribute__((aligned(x))) +#define SA(X) static_assert ((X),#X) + +template +void type_alignment(const T&) { + struct { char c; T t; } s; + SA((char*)&s.t - (char*)&s.c == 8); +} + +int main() { + typedef char unaligned[15]; + typedef char aligned[15] ALIGNED(8); + + aligned z; + type_alignment(z); + type_alignment(z); +}