[PATCH] D124571: Avoid strict aliasing violation on type punning inside llvm::PointerIntPair

Breno Rodrigues Guimaraes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 14 17:03:58 PDT 2022


brenoguim updated this revision to Diff 429495.
brenoguim added a comment.

Since `PointerIntPair` may hold non-trivially-constructible types (like another `PointerIntPair`), I added a placement new of the inner type to make sure we comply with the standard by explicitly starting the lifetime of the `Ptr` object in the storage. This allows me to `reinterpret_cast` this storage as `Ptr` in `getPointerAddress`.

I also added static asserts that the inner type is trivially copy constructible, move constructible and destructible, that gives me guarantees that the compiler generated the destructor and copy/move constructors of `PunnedPointer` are correct.


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

https://reviews.llvm.org/D124571

Files:
  llvm/include/llvm/ADT/PointerIntPair.h
  llvm/unittests/ADT/PointerIntPairTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124571.429495.patch
Type: text/x-patch
Size: 3111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220515/be2eef46/attachment.bin>


More information about the llvm-commits mailing list