[PATCH] libstdc++: Clear padding bits in atomic compare_exchange

Jakub Jelinek jakub@redhat.com
Tue Nov 2 07:49:51 GMT 2021


On Mon, Nov 01, 2021 at 06:25:45PM -0700, Thomas Rodgers via Gcc-patches wrote:
> +    template<typename _Tp>
> +      constexpr bool
> +      __maybe_has_padding()
> +      {
> +#if __has_builtin(__has_unique_object_representations)
> +	return !__has_unique_object_representations(_Tp)
> +	  && !is_floating_point<_Tp>::value;
> +#else
> +	return true;
> +#endif

I'm not sure I understand the && !is_floating_point<_Tp>::value.
Yes, float and double will never have padding, but long double often
will, e.g. on x86 or ia64 (but e.g. not on ppc, s390x, etc.).
So, unless we want to play with numeric_limits, it should be either
just return !__has_unique_object_representations(_Tp);
or return !__has_unique_object_representations(_Tp)
	  && (!is_floating_point<_Tp>::value
	      || is_same<__remove_cv_t<_Tp>,long double>::value);
or, with numeric_limits test numeric_limits<_Tp>::digits == 64
(but I'm sure Jonathan will not want including such a header dependency
unless it is already included).
Or I can always provide a new __builtin_clear_padding_p ...

	Jakub



More information about the Gcc-patches mailing list