[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
Thu May 5 17:37:16 PDT 2022


brenoguim added a comment.

> (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 [...]".)

I was referring to the other use of `std::launder`. From https://en.cppreference.com/w/cpp/utility/launder :

  Obtaining a pointer to an object created by placement new from a pointer to an object providing storage for that object.

But indeed we did not call placement new, so that doesn't apply.

And now, I found the blessing to not call the placement new:

  The lifetime of an object of type T begins when:
  (1.1) — storage with the proper alignment and size for type T is obtained, and
  (1.2) — if the object has non-vacuous initialization, its initialization is complete,

So by instantiating the array of `char` we can say the lifetime of `Ptr` already started. No need for placement new.

Now I'm more confident this is the right way to go.


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

https://reviews.llvm.org/D124571



More information about the llvm-commits mailing list