diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index afa83e18935c..b90606103c04 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10429,6 +10429,8 @@ def err_conflicting_sycl_kernel_attributes : Error< "conflicting attributes applied to a SYCL kernel">; def err_conflicting_sycl_function_attributes : Error< "%0 attribute conflicts with '%1' attribute">; +def err_sycl_typecheck_zero_array_size : Error< + "zero-length arrays are not permitted in SYCL kernels">; def err_sycl_x_y_z_arguments_must_be_one : Error< "%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">; def err_intel_attribute_argument_is_not_in_range: Error< diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 438956488ad5..af83397df941 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2340,6 +2340,13 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, << ArraySize->getSourceRange(); ASM = ArrayType::Normal; } + + // SYCL kernels reject zero length arrays + if (getLangOpts().SYCLIsDevice) { + SYCLDiagIfDeviceCode(ArraySize->getBeginLoc(), + diag::err_sycl_typecheck_zero_array_size) + << ArraySize->getSourceRange(); + } } else if (!T->isDependentType() && !T->isVariablyModifiedType() && !T->isIncompleteType() && !T->isUndeducedType()) { // Is the array too large? diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index 658395e92c3f..61a7e499aa93 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -143,6 +143,9 @@ void usage(myFuncDef functionPtr) { // expected-error@+1 {{__float128 is not supported on this target}} __float128 A; + + // expected-error@+1 {{zero-length arrays are not permitted in SYCL kernels}} + int BadArray[0]; } namespace ns {