Skip to content

[SYCL] Restriction : cannot capture class static var in kernel code #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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