Commit 4cbaaa45 by Jonathan Wakely Committed by Jonathan Wakely

re PR libstdc++/65147 (alignment of std::atomic object is not correct)

2015-04-09  Jonathan Wakely  <jwakely@redhat.com>
	    Richard Henderson  <rth@redhat.com>

	PR libstdc++/65147
	* include/bits/atomic_base.h (__atomic_base<_ITp>): Increase
	alignment.
	* include/std/atomic (atomic): For types with a power of two size set
	alignment to at least the size.
	* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number.
	* testsuite/29_atomics/atomic/65147.cc: New.
	* testsuite/29_atomics/atomic_integral/65147.cc: New.

Co-Authored-By: Richard Henderson <rth@redhat.com>

From-SVN: r221945
parent 3ba99d8a
2015-04-09 Jonathan Wakely <jwakely@redhat.com>
Richard Henderson <rth@redhat.com>
PR libstdc++/65147
* include/bits/atomic_base.h (__atomic_base<_ITp>): Increase
alignment.
* include/std/atomic (atomic): For types with a power of two size set
alignment to at least the size.
* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number.
* testsuite/29_atomics/atomic/65147.cc: New.
* testsuite/29_atomics/atomic_integral/65147.cc: New.
2015-04-09 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2015-04-09 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* config/abi/post/solaris2.10/baseline_symbols.txt: Regenerate. * config/abi/post/solaris2.10/baseline_symbols.txt: Regenerate.
......
...@@ -240,7 +240,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -240,7 +240,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private: private:
typedef _ITp __int_type; typedef _ITp __int_type;
__int_type _M_i; static constexpr int _S_alignment =
sizeof(_ITp) > alignof(_ITp) ? sizeof(_ITp) : alignof(_ITp);
alignas(_S_alignment) __int_type _M_i;
public: public:
__atomic_base() noexcept = default; __atomic_base() noexcept = default;
......
...@@ -165,18 +165,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -165,18 +165,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct atomic struct atomic
{ {
private: private:
// Align 1/2/4/8/16-byte types the same as integer types of that size. // Align 1/2/4/8/16-byte types to at least their size.
// This matches the alignment effects of the C11 _Atomic qualifier.
static constexpr int _S_min_alignment static constexpr int _S_min_alignment
= sizeof(_Tp) == sizeof(char) ? alignof(char) = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16
: sizeof(_Tp) == sizeof(short) ? alignof(short) ? 0 : sizeof(_Tp);
: sizeof(_Tp) == sizeof(int) ? alignof(int)
: sizeof(_Tp) == sizeof(long) ? alignof(long)
: sizeof(_Tp) == sizeof(long long) ? alignof(long long)
#ifdef _GLIBCXX_USE_INT128
: sizeof(_Tp) == sizeof(__int128) ? alignof(__int128)
#endif
: 0;
static constexpr int _S_alignment static constexpr int _S_alignment
= _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp); = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
......
...@@ -27,4 +27,4 @@ struct X { ...@@ -27,4 +27,4 @@ struct X {
char stuff[0]; // GNU extension, type has zero size char stuff[0]; // GNU extension, type has zero size
}; };
std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 189 } std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 181 }
// 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
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++11" }
// { dg-do compile }
#include <atomic>
struct S16 {
char c[16];
};
static_assert( alignof(std::atomic<S16>) >= 16,
"atomic<S16> must be aligned to at least its size" );
// 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
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++11" }
// { dg-do compile }
#include <atomic>
static_assert( alignof(std::atomic<char>) >= sizeof(char),
"atomic<char> must be aligned to at least its size" );
static_assert( alignof(std::atomic<short>) >= sizeof(short),
"atomic<short> must be aligned to at least its size" );
static_assert( alignof(std::atomic<int>) >= sizeof(int),
"atomic<int> must be aligned to at least its size" );
static_assert( alignof(std::atomic<long>) >= sizeof(long),
"atomic<long> must be aligned to at least its size" );
static_assert( alignof(std::atomic<long long>) >= sizeof(long long),
"atomic<long long> must be aligned to at least its size" );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment