xref: /llvm-project/clang/test/SemaHIP/zero-sized-device-array.hip (revision 854d7301f989dd1e3c838ef4f48cb57bb7d496e0)
1// REQUIRES: amdgpu-registered-target
2// RUN:  %clang_cc1 -fsyntax-only -x hip -fcuda-is-device -verify -triple amdgcn %s
3#define __device__ __attribute__((device))
4#define __host__ __attribute__((host))
5#define __global__ __attribute__((global))
6#define __shared__ __attribute__((shared))
7
8typedef float ZEROARR[0];
9
10float global_array[0];
11
12__global__ void global_fun() {
13    extern __shared__ float externArray[];
14    ZEROARR TypeDef; // expected-error {{zero-length arrays are not permitted in HIP device code}}
15    float array[0];  // expected-error {{zero-length arrays are not permitted in HIP device code}}
16}
17
18// should not throw error for host side code.
19__host__ void host_fun() {
20    float array[0];
21}
22
23template <typename Ty, unsigned Size>
24__device__ void templated()
25{
26   Ty arr[Size];  // expected-error {{zero-length arrays are not permitted in HIP device code}}
27}
28
29__host__ __device__ void host_dev_fun()
30{
31    float array[0]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
32}
33
34__device__ void device_fun()
35{
36    __shared__ float array[0]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
37    templated<int,0>(); // expected-note {{in instantiation of function template specialization 'templated<int, 0U>' requested here}}
38}
39