Skip to content

Commit

Permalink
[SYCL] Restriction : cannot capture class static var in kernel code
Browse files Browse the repository at this point in the history
Signed-off-by: Melanie Blower <melanie.blower@intel.com>
  • Loading branch information
Melanie Blower authored and vladimirlaz committed Apr 8, 2019
1 parent 82fead6 commit 11c512c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
bool VisitMemberExpr(MemberExpr *E) {
if (VarDecl *VD = dyn_cast<VarDecl>(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;
}
Expand All @@ -188,7 +188,10 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
CheckSYCLType(E->getType(), E->getSourceRange());
if (VarDecl *VD = dyn_cast<VarDecl>(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<ParmVarDecl>(VD))
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
<< KernelGlobalVariable;
Expand Down
14 changes: 12 additions & 2 deletions clang/test/SemaSYCL/sycl-restrict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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}}
Expand All @@ -169,7 +178,8 @@ template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
a_type ab;
use2(ab);
a_type *p;
use2(ab, p);
}

int main() {
Expand Down

0 comments on commit 11c512c

Please sign in to comment.