llvm-project/clang/test/SemaHIP/zero-sized-device-array.hip
Vigneshwar Jayakumar 854d7301f9
[Clang/AMDGPU] Zero sized arrays not allowed in HIP device code. (#113470)
Added diagnosis to throw error when zero sized arrays are used in the
HIP device code. SWDEV-449592

---------

Co-authored-by: vigneshwar jayakumar <vigneshwar.jayakumar@amd.com>
2024-11-27 14:20:07 -06:00

39 lines
1.3 KiB
Plaintext

// REQUIRES: amdgpu-registered-target
// RUN: %clang_cc1 -fsyntax-only -x hip -fcuda-is-device -verify -triple amdgcn %s
#define __device__ __attribute__((device))
#define __host__ __attribute__((host))
#define __global__ __attribute__((global))
#define __shared__ __attribute__((shared))
typedef float ZEROARR[0];
float global_array[0];
__global__ void global_fun() {
extern __shared__ float externArray[];
ZEROARR TypeDef; // expected-error {{zero-length arrays are not permitted in HIP device code}}
float array[0]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
}
// should not throw error for host side code.
__host__ void host_fun() {
float array[0];
}
template <typename Ty, unsigned Size>
__device__ void templated()
{
Ty arr[Size]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
}
__host__ __device__ void host_dev_fun()
{
float array[0]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
}
__device__ void device_fun()
{
__shared__ float array[0]; // expected-error {{zero-length arrays are not permitted in HIP device code}}
templated<int,0>(); // expected-note {{in instantiation of function template specialization 'templated<int, 0U>' requested here}}
}