[PATCH] D124571: Avoid strict aliasing violation on type punning inside llvm::PointerIntPair
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 12:52:04 PDT 2022
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.
LGTM
> Although, there we might be missing two things to be truly correct:
>
> - May need to call placement new. It's a noop being a trivial type, but still...
> - May need to call std::launder to indicate an object of type Ptr is supposed to be there. But that's C++17
You could implement `operator=` using something like `if (isAligned(V)) new (Data) Ptr(reinterpret_cast<Ptr>(V)); else new (Data) intptr_t(V);`, sure. But [cstring.syn] says memcpy implicitly creates objects, so I think it's effectively the same result.
(std::launder isn't relevant here. From [ptr.launder]: "If a new object is created in storage occupied by an existing object of the same type, a pointer to the original object can be used to refer to the new object unless its complete object is a const object or it is a base class subobject [...]".)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124571/new/
https://reviews.llvm.org/D124571
More information about the llvm-commits
mailing list