xref: /llvm-project/clang/test/SemaCUDA/vla.cu (revision 84a3aadf0f2483dde0acfc4e79f2a075a5f35bd1)
1 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -verify -Wno-vla %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -DHOST -Wno-vla %s
3 
4 #ifndef __CUDA_ARCH__
5 // expected-no-diagnostics
6 #endif
7 
8 #include "Inputs/cuda.h"
9 
host(int n)10 void host(int n) {
11   int x[n];
12 }
13 
device(int n)14 __device__ void device(int n) {
15   int x[n];
16 #ifdef __CUDA_ARCH__
17   // expected-error@-2 {{cannot use variable-length arrays in __device__ functions}}
18 #endif
19 }
20 
hd(int n)21 __host__ __device__ void hd(int n) {
22   int x[n];
23 #ifdef __CUDA_ARCH__
24   // expected-error@-2 {{cannot use variable-length arrays in __host__ __device__ functions}}
25 #endif
26 }
27 
28 // No error because never codegen'ed for device.
hd_inline(int n)29 __host__ __device__ inline void hd_inline(int n) {
30   int x[n];
31 }
call_hd_inline()32 void call_hd_inline() { hd_inline(42); }
33