From eaa10ea40fc6786c2bab138512d796857371dad4 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Sat, 15 Feb 2020 11:22:51 -0800 Subject: [PATCH] disallow zero length arrays in SYCL kernels Signed-off-by: Chris Perkins --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaType.cpp | 7 +++++++ clang/test/SemaSYCL/sycl-restrict.cpp | 3 +++ 3 files changed, 12 insertions(+) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index afa83e18935c7..b90606103c04e 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 438956488ad5f..af83397df9418 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 658395e92c3ff..61a7e499aa936 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 {