This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC 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>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, Andrew MacLeod <amacleod at redhat dot com>
- Date: Wed, 25 Mar 2015 11:36:45 -0700
- Subject: Re: [libstdc++/65033] Give alignment info to libatomic
- Authentication-results: sourceware.org; auth=none
- References: <54DD19B7 dot 6060401 at redhat dot com> <20150218121512 dot GI3360 at redhat dot com> <20150325162244 dot GF9755 at redhat dot com>
On 03/25/2015 09:22 AM, Jonathan Wakely wrote:
> private:
> - _Tp _M_i;
> + // Align 1/2/4/8/16-byte types the same as integer types of that size.
> + // This matches the alignment effects of the C11 _Atomic qualifier.
> + static constexpr int _S_alignment
> + = sizeof(_Tp) == sizeof(char) ? alignof(char)
> + : sizeof(_Tp) == sizeof(short) ? alignof(short)
> + : 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
> + : alignof(_Tp);
> +
> + alignas(_S_alignment) _Tp _M_i;
Surely not by reducing a larger alignment applied to _Tp.
I.e.
static constexpr int _S_min_alignment
= sizeof(_Tp) == sizeof(char) ? alignof(char)
: sizeof(_Tp) == sizeof(short) ? alignof(short)
: 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
= _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
r~