[PATCH] D87974: [Builtin] Add __builtin_zero_non_value_bits.

Jonathan Wakely via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 8 00:53:58 PST 2020


jwakely added a comment.

In D87974#2438723 <https://reviews.llvm.org/D87974#2438723>, @zoecarver wrote:

> In D87974#2438682 <https://reviews.llvm.org/D87974#2438682>, @BillyONeal wrote:
>
>>> Are they actually the same, with the same handling of corner cases like unions and tail padding?
>>> There's more to this than just the name, and if they aren't the same, it seems better to have two names.
>>
>> They are both implementing the same C++ feature, with the same desired semantics of zeroing out any bits in the object representation that aren't in the value representation. If they differ, one or the other would have a bug.

Do they support non-trivially copyable types? That isn't required for the atomic compare exchange feature, but is relevant for a feature exposed to users. What about extensions like zero-sized arrays or C99 flexible array members?

> I agree, they either need to be identical (including corner cases) or there needs to be two of them (i.e., GCC ships both `__builtin_zero_non_value_bits` and `__builtin_clear_padding` and the first is the same as MSVC, Clang, and NVCC).

GCC doesn't need to support both. It only works with libstdc++ so it only needs to support the one used by libstdc++ (although there is a patch to add `-stdlib=libc++` to GCC).

If libstdc++ uses `__has_builtin` to check what the compiler supports then Clang doesn't even need to support GCC's built-in, because libstdc++ wouldn't use it if not supported (and could use `__builtin_zero_non_value_bits` instead when supported).

The Intel compiler would need to support both though.

>>> Is there a specification for __builtin_zero_non_value_bits available somewhere?
>>
>> I don't know if there is a formal spec for it beyond the actual C++ standard.
>
> I think P0528 is the relevant paper but other than that, no, there's not a spec. I think that's going to be the most time sensitive part of implementing this: coming up with the spec and making sure all the tests pass on all the implementations.

GCC has publicly available documentation describing its built-in, and publicly available tests for it. That's the kind of spec I'm looking for.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87974/new/

https://reviews.llvm.org/D87974



More information about the cfe-commits mailing list