From patchwork Tue Mar 31 13:41:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 456619 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 51D38140187 for ; Wed, 1 Apr 2015 00:41:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=mxKQbQ8Z; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=waNaIhV6cTLvBi7cP PlTMWek1ucbOsbg+ReWdb72K4DpVjIh8k1CY5+rAe4gZaA2zojFsagl4jwfrhhJt QCo1i6JGZH3oscZCRsObZQhD9DdAMsMVo6RyMJSTdFLaL8K6FsQKZ26v5fzTpXvH 8rFX7PAZCSRF1f37+satrZMmoU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=x3YdFgJaqixaJPFzy4QVjke p2Ls=; b=mxKQbQ8ZtVxkgCgi0T93+30ghofFcoFP+jUxLTIGbipy4mSiwRCADQL y62k0AV06hGVk/Ets6BGKQRbsl7hmRJnc66Nlj/21/IBSK0eRI/4PAuwS+41cV87 61rPjINbLAsi9ylWSmKHgv3zNhAbsJXUNNnBag3DgEunlV3Xt+UU= Received: (qmail 117578 invoked by alias); 31 Mar 2015 13:41:42 -0000 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 Received: (qmail 117466 invoked by uid 89); 31 Mar 2015 13:41:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 31 Mar 2015 13:41:40 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2VDfcbi004792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 31 Mar 2015 09:41:38 -0400 Received: from localhost (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2VDfbEj015120; Tue, 31 Mar 2015 09:41:37 -0400 Date: Tue, 31 Mar 2015 14:41:36 +0100 From: Jonathan Wakely To: Richard Henderson Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, Andrew MacLeod Subject: Re: [libstdc++/65033] Give alignment info to libatomic Message-ID: <20150331134136.GS9755@redhat.com> References: <54DD19B7.6060401@redhat.com> <20150218121512.GI3360@redhat.com> <20150325162244.GF9755@redhat.com> <5513003D.3040107@redhat.com> <20150325184913.GH9755@redhat.com> <551306C1.6060702@redhat.com> <20150326132147.GL9755@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150326132147.GL9755@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) On 26/03/15 13:21 +0000, Jonathan Wakely wrote: >This includes your fix to avoid decreasing alignment, but I didn't add >a test for that as I couldn't make it fail on any of the targets I >test on. >commit f796769ad20c0353490b9f1a7e019e2f0c1771fb >Author: Jonathan Wakely >Date: Wed Sep 3 15:39:53 2014 +0100 > > PR libstdc++/62259 > PR libstdc++/65147 > * include/std/atomic (atomic): Increase alignment for types with > the same size as one of the integral types. > * testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number. > * testsuite/29_atomics/atomic/62259.cc: New. My patch was not sufficient to fix 65147, because I didn't increase the alignment of the std::atomic specializations, and std::atomic<16-byte type> is only aligned correctly if __int128 is supported, which isn't true on x86 and other 32-bit targets. This is the best I've come up with, does anyone have any better ideas than the #else branch to hardcode alignment of 16-byte types to 16? commit d0ccfb0523066c69f3d22d9cdd617a139c57f9e1 Author: Jonathan Wakely Date: Mon Mar 30 14:28:01 2015 +0100 PR libstdc++/65147 * include/bits/atomic_base.h (__atomic_base): Align as underlying type. * include/std/atomic (atomic): Hardcode alignment for 16-byte types when __int128 is not available. * testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number. * testsuite/29_atomics/atomic/65147.cc: New. diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index 8104c98..48931ac 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -235,7 +235,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 8 bytes, since that is what GCC built-in functions for atomic // memory access expect. template - struct __atomic_base + struct alignas(_ITp) __atomic_base { private: typedef _ITp __int_type; @@ -559,7 +559,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Partial specialization for pointer types. template - struct __atomic_base<_PTp*> + struct alignas(_PTp*) __atomic_base<_PTp*> { private: typedef _PTp* __pointer_type; diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 88c8b17..2b09477 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -175,6 +175,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : sizeof(_Tp) == sizeof(long long) ? alignof(long long) #ifdef _GLIBCXX_USE_INT128 : sizeof(_Tp) == sizeof(__int128) ? alignof(__int128) +#else + : sizeof(_Tp) == 16 ? 16 #endif : 0; diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc b/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc index 6f618a0..f755be0 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc @@ -27,4 +27,4 @@ struct X { char stuff[0]; // GNU extension, type has zero size }; -std::atomic a; // { dg-error "not supported" "" { target *-*-* } 189 } +std::atomic a; // { dg-error "not supported" "" { target *-*-* } 191 } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/65147.cc b/libstdc++-v3/testsuite/29_atomics/atomic/65147.cc new file mode 100644 index 0000000..bb92513 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/65147.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// PR libstdc++65147 + +#include + +static_assert( alignof(std::atomic) == alignof(short), + "atomic short must be aligned like short" ); + +static_assert( alignof(std::atomic) == alignof(int), + "atomic int must be aligned like int" ); + +static_assert( alignof(std::atomic) == alignof(long), + "atomic long must be aligned like long" ); + +static_assert( alignof(std::atomic) == alignof(long long), + "atomic long long must be aligned like long long" ); + +struct S { + char s[16]; +}; + +static_assert( alignof(std::atomic) > 1, + "atomic 16-byte struct must not be aligned like char" );