This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [libstdc++/65033] Give alignment info to libatomic
- From: Richard Henderson <rth at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>, Hans-Peter Nilsson <hp at bitrange dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 03 Apr 2015 12:13:12 -0700
- Subject: Re: [libstdc++/65033] Give alignment info to libatomic
- Authentication-results: sourceware.org; auth=none
- References: <54DD19B7 dot 6060401 at redhat dot com> <alpine dot BSF dot 2 dot 02 dot 1504022240580 dot 40679 at arjuna dot pair dot com> <alpine dot BSF dot 2 dot 02 dot 1504030518160 dot 69548 at arjuna dot pair dot com> <20150403141333 dot GY9755 at redhat dot com>
On 04/03/2015 07:13 AM, Jonathan Wakely wrote:
> +++ b/libstdc++-v3/include/std/atomic
> @@ -165,9 +165,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> struct atomic
> {
> 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 the natural alignment of that size.
> // This matches the alignment effects of the C11 _Atomic qualifier.
> - static constexpr int _S_min_alignment
> + static constexpr int _S_int_alignment
> = sizeof(_Tp) == sizeof(char) ? alignof(char)
> : sizeof(_Tp) == sizeof(short) ? alignof(short)
> : sizeof(_Tp) == sizeof(int) ? alignof(int)
> @@ -178,6 +178,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> #endif
> : 0;
>
> + static constexpr int _S_min_alignment
> + = _S_int_alignment > sizeof(_Tp) ? _S_int_alignment : sizeof(_Tp);
> +
This doesn't work for non-power-of-two sized _Tp.
Again, we don't have *any* target for which alignof(integer) > sizeof(integer).
So if you care about forcing natural alignment, don't bother with the alignof
on the integrals, as you're doing with _S_int_alignment at the moment.
r~