diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index c6ebb7e1d888..948ba9a71241 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -177,7 +177,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor { bool VisitMemberExpr(MemberExpr *E) { if (VarDecl *VD = dyn_cast(E->getMemberDecl())) { bool IsConst = VD->getType().getNonReferenceType().isConstQualified(); - if (VD->isStaticDataMember() && !IsConst) + if (!IsConst && VD->isStaticDataMember()) SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict) << KernelNonConstStaticDataVariable; } @@ -188,7 +188,10 @@ class MarkDeviceFunction : public RecursiveASTVisitor { CheckSYCLType(E->getType(), E->getSourceRange()); if (VarDecl *VD = dyn_cast(E->getDecl())) { bool IsConst = VD->getType().getNonReferenceType().isConstQualified(); - if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() && + if (!IsConst && VD->isStaticDataMember()) + SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict) + << KernelNonConstStaticDataVariable; + else if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() && !VD->isStaticDataMember() && !isa(VD)) SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict) << KernelGlobalVariable; diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index d35805bd57ba..8589bf55bd4f 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -90,6 +90,12 @@ typedef struct A { static int stat_member; const static int const_stat_member; constexpr static int constexpr_stat_member=0; + + int fm(void) + { + // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}} + return stat_member; + } } a_type; @@ -147,12 +153,15 @@ extern "C++" { } } -int use2 ( a_type ab ) { +int use2 ( a_type ab, a_type *abp ) { if (ab.constexpr_stat_member) return 2; if (ab.const_stat_member) return 1; // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}} if (ab.stat_member) return 0; + // expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}} + if (abp->stat_member) return 0; + if (ab.fm()) return 0; // expected-error@+1 {{SYCL kernel cannot use a global variable}} return another_global ; // expected-error@+1 {{SYCL kernel cannot use a global variable}} @@ -169,7 +178,8 @@ template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { kernelFunc(); a_type ab; - use2(ab); + a_type *p; + use2(ab, p); } int main() {