diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index b123951fb58fa..8b8cf8319e93a 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -1298,6 +1298,18 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler { return isValid(); } + bool handlePointerType(FieldDecl *FD, QualType FieldTy) final { + while (FieldTy->isAnyPointerType()) { + FieldTy = QualType{FieldTy->getPointeeOrArrayElementType(), 0}; + if (FieldTy->isVariableArrayType()) { + Diag.Report(FD->getLocation(), diag::err_vla_unsupported); + IsInvalid = true; + break; + } + } + return isValid(); + } + bool handleOtherType(FieldDecl *FD, QualType FieldTy) final { Diag.Report(FD->getLocation(), diag::err_bad_kernel_param_type) << FieldTy; IsInvalid = true; diff --git a/clang/test/SemaSYCL/pointer-to-vla.cpp b/clang/test/SemaSYCL/pointer-to-vla.cpp new file mode 100644 index 0000000000000..c8a492b9b32e7 --- /dev/null +++ b/clang/test/SemaSYCL/pointer-to-vla.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64 -fsyntax-only -Wno-sycl-2017-compat -verify %s +// +// This test checks if compiler reports compilation error on an attempt to pass +// a pointer to VLA as kernel argument + +#include "Inputs/sycl.hpp" + +void foo(unsigned X) { + using VLATy = float(*)[X]; + VLATy PtrToVLA; + cl::sycl::kernel_single_task([=]() { + // expected-error@+1 {{variable length arrays are not supported for the current target}} + (void)PtrToVLA; + }); +}