[libstdc++/65033] Give alignment info to libatomic

Richard Henderson rth@redhat.com
Wed Mar 25 18:36:00 GMT 2015


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~



More information about the Libstdc++ mailing list