Skip to content

Commit 11c512c

Browse files
Melanie Blowervladimirlaz
Melanie Blower
authored andcommitted
[SYCL] Restriction : cannot capture class static var in kernel code
Signed-off-by: Melanie Blower <[email protected]>
1 parent 82fead6 commit 11c512c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
177177
bool VisitMemberExpr(MemberExpr *E) {
178178
if (VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) {
179179
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
180-
if (VD->isStaticDataMember() && !IsConst)
180+
if (!IsConst && VD->isStaticDataMember())
181181
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
182182
<< KernelNonConstStaticDataVariable;
183183
}
@@ -188,7 +188,10 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
188188
CheckSYCLType(E->getType(), E->getSourceRange());
189189
if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
190190
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
191-
if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
191+
if (!IsConst && VD->isStaticDataMember())
192+
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
193+
<< KernelNonConstStaticDataVariable;
194+
else if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
192195
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD))
193196
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
194197
<< KernelGlobalVariable;

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ typedef struct A {
9090
static int stat_member;
9191
const static int const_stat_member;
9292
constexpr static int constexpr_stat_member=0;
93+
94+
int fm(void)
95+
{
96+
// expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
97+
return stat_member;
98+
}
9399
} a_type;
94100

95101

@@ -147,12 +153,15 @@ extern "C++" {
147153
}
148154
}
149155

150-
int use2 ( a_type ab ) {
156+
int use2 ( a_type ab, a_type *abp ) {
151157

152158
if (ab.constexpr_stat_member) return 2;
153159
if (ab.const_stat_member) return 1;
154160
// expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
155161
if (ab.stat_member) return 0;
162+
// expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
163+
if (abp->stat_member) return 0;
164+
if (ab.fm()) return 0;
156165
// expected-error@+1 {{SYCL kernel cannot use a global variable}}
157166
return another_global ;
158167
// expected-error@+1 {{SYCL kernel cannot use a global variable}}
@@ -169,7 +178,8 @@ template <typename name, typename Func>
169178
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
170179
kernelFunc();
171180
a_type ab;
172-
use2(ab);
181+
a_type *p;
182+
use2(ab, p);
173183
}
174184

175185
int main() {

0 commit comments

Comments
 (0)