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" );