[libcxx-commits] [PATCH] D58004: Bit-casting object representations (p0476r2)

Erik Pilkington via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 13 10:44:45 PST 2019


erik.pilkington added a comment.

In D58004#1395763 <https://reviews.llvm.org/D58004#1395763>, @zoecarver wrote:

> @erik.pilkington friendly ping, have you made any progress on compiler support?


I'm planning on implementing this, but haven't quite gotten around to it yet. The idea is a builtin spelt `__builtin_bit_cast(T, expr)`, that would just IRGen to a simple memcpy. In the frontend's constant evaluator (`lib/AST/ExprConstant.cpp`), we need to map from an `APValue` of one type to an `APValue` of another, which can get a little hairy (especially since we want to evaluate it however the target would). If you're interested in taking a look at this I can give you a more detailed brain dump and dig up some WIP patches.

> A more general question: `bit_cast` is only available in C++20 which supports the `memcpy` function as a `constexpr`, does that resolve the issue or would there be other benefits form compiler support (no type punning, etc.)?

constexpr memcpy doesn't do type-punning, so compiler support is still needed in general.


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

https://reviews.llvm.org/D58004





More information about the libcxx-commits mailing list