[clang] [Clang/AMDGPU] Allow zero sized arrays in HIP device code (PR #195716)
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue May 5 06:36:46 PDT 2026
yxsamliu wrote:
Thanks for looking into this.
I agree that ordinary `non-__shared__` zero-sized arrays have a clear GNU-extension semantic: they occupy zero bytes, can act as an anchor to a distinct address, and should not need a HIP-specific diagnostic.
The motivation for the existing diagnostic came from customer reports about zero-sized `__shared__` arrays, where code accidentally wrote something like `__shared__ T x[0]` and confused it with the extensively used dynamic shared-memory form `extern __shared__ T x[];` that led to unclear failures, so the request was for a better compile-time diagnostic.
A possible compromise is to allow `non-__shared__` zero-sized arrays in HIP device code, but keep a diagnostic for zero-sized `__shared__` variables to discourage that particular misuse. That would also address the issue my PR was trying to fix, since host/device functions in C++ headers could still use ordinary non-shared zero-sized arrays without being rejected during device compilation
https://github.com/llvm/llvm-project/pull/195716
More information about the cfe-commits
mailing list