[PATCH] D151087: [Clang] Permit address space casts with 'reinterpret_cast' in C++

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 09:34:43 PDT 2023


ebevhan added a comment.

In D151087#4360859 <https://reviews.llvm.org/D151087#4360859>, @jhuber6 wrote:

> You can have address spaced in freestanding C++, they just need to be assigned according to the backens, e.g. https://godbolt.org/z/ahazae6Ta. And I don't think that's a desirable solution because it would require a language extension to cover a use-case that isn't disallowed by the C++ standard anyway. I don't see a reason why we shouldn't be able to do this directly.

The problem with reinterpret_cast is that it isn't sufficient for arbitrary address space configurations. The first issue is that reinterpret_cast inherently performs a bitcast, which is not allowed if the pointers to address spaces being casted between are of different sizes. Then, the reinterpret_cast would suddenly have different semantics than a bitcast.

Another (contrived, but possible) case is if you have address spaces on a target where the spaces overlap, but with different semantics between them, and the pointers have the same size. What is now a reinterpret_cast? An address space conversion, or a bitcast? It's not as straightforward as it might seem.

Clang hasn't needed to formalize all of the address space behavior because it's managed to piggyback off of the language semantics provided by OpenCL, and no targets really have had a need for it. Once you start looking at the target AS stuff on its own, you realize it's not really that well defined, and making it even less defined by allowing arbitrary conversions isn't the solution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151087



More information about the cfe-commits mailing list