[clang] [clang-tools-extra] [Clang] Use TargetInfo when deciding is an address space is compatible (PR #115777)
Alex Voicu via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 07:10:24 PST 2024
AlexVlx wrote:
> For AMDGPU and NVPTX, pointers are allowed to drop their address spaces transparently. So, `void AS(3) *` can convert to `void *`. Languages like CUDA and SYCL and HIP use these 'language' address spaces to describe exactly this, but my assertion is that it's more of a function of the target. I'm sure @arsenm could explain the underlying implementation more deeply.
I think this view is somewhat problematic, as it mixes target concepts and language concepts in a dangerous way. Neither CUDA, nor HIP nor SYCL (AFAICT) do what is described, all of those are AS agnostic *languages*. Unlike e.g. OpenCL, a `__shared__` `int` is just an `int`, whereas the way in which we handle ASes in Clang / on the language level is typeful i.e. a `__private` `int` is not an `int` in OpenCL. An explicit pointer to a numbered AS generally does not blindly convert to a vanilla pointer in HIP or CUDA, observe e.g.: https://gcc.godbolt.org/z/cY4aa9cx8. So no, HIP and CUDA don't actually allow this behaviour per se. They chose different linguistic defaults. Furthermore, it's tricky to uplift target semantics into linguistic ones, for a language that is supposed to be generic.
I don't necessarily mind this in this form, as an opt-in "here-be-dragons" mechanism which gets one into rather unspecified non-standard language dialect/extension territory. I do object to the very relaxed take that it is sound and just how things should work because some targets allow it. We should probably not try to sneakily back-legislate what standard C/C++ are.
https://github.com/llvm/llvm-project/pull/115777
More information about the cfe-commits
mailing list