Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7060,10 +7060,13 @@ NamedDecl *Sema::ActOnVariableDeclarator(

// Static variables declared inside SYCL device code must be const or
// constexpr
if (getLangOpts().SYCLIsDevice && SCSpec == DeclSpec::SCS_static &&
!R.isConstant(Context))
if (getLangOpts().SYCLIsDevice) {
if (SCSpec == DeclSpec::SCS_static && !R.isConstant(Context))
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_sycl_restrict)
<< Sema::KernelNonConstStaticDataVariable;
else if (NewVD->getTSCSpec() == DeclSpec::TSCS_thread_local)
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_thread_unsupported);
}

switch (D.getDeclSpec().getConstexprSpecifier()) {
case CSK_unspecified:
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,17 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
ObjCInterfaceDecl *ClassReceiver) {
if (getLangOpts().SYCLIsDevice) {
if (auto VD = dyn_cast<VarDecl>(D)) {
bool IsConst = VD->getType().isConstant(Context);
if (VD->getTLSKind() != VarDecl::TLS_None)
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_thread_unsupported);

if (VD->getStorageClass() == SC_Static &&
!VD->getType().isConstant(Context))
!IsConst)
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
<< Sema::KernelNonConstStaticDataVariable;
else if (VD->hasGlobalStorage() && !isa<ParmVarDecl>(VD) && !IsConst)
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
<< Sema::KernelGlobalVariable;
}
}

Expand Down
8 changes: 0 additions & 8 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {

CheckSYCLType(E->getType(), E->getSourceRange());
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
if (VD->getTLSKind() != VarDecl::TLS_None)
SemaRef.Diag(E->getLocation(), diag::err_thread_unsupported);
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
<< Sema::KernelGlobalVariable;
}
if (!VD->isLocalVarDeclOrParm() && VD->hasGlobalStorage()) {
VD->addAttr(SYCLDeviceAttr::CreateImplicit(SemaRef.Context));
SemaRef.addSyclDeviceDecl(VD);
Expand Down
49 changes: 49 additions & 0 deletions clang/test/SemaSYCL/prohibit-thread-local.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -std=c++17 %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is c++17 needed here?


thread_local const int prohobit_ns_scope = 0;
thread_local int prohobit_ns_scope2 = 0;
thread_local const int allow_ns_scope = 0;

struct S {
static const thread_local int prohibit_static_member;
static thread_local int prohibit_static_member2;
};

struct T {
static const thread_local int allow_static_member;
};

void foo() {
// expected-error@+1{{thread-local storage is not supported for the current target}}
thread_local const int prohibit_local = 0;
// expected-error@+1{{thread-local storage is not supported for the current target}}
thread_local int prohibit_local2;
}

void bar() { thread_local int allow_local; }

void usage() {
// expected-note@+1 {{called by}}
foo();
// expected-error@+1 {{thread-local storage is not supported for the current target}}
(void)prohobit_ns_scope;
// expected-error@+2 {{SYCL kernel cannot use a non-const global variable}}
// expected-error@+1 {{thread-local storage is not supported for the current target}}
(void)prohobit_ns_scope2;
// expected-error@+1 {{thread-local storage is not supported for the current target}}
(void)S::prohibit_static_member;
// expected-error@+2 {{SYCL kernel cannot use a non-const static data variable}}
// expected-error@+1 {{thread-local storage is not supported for the current target}}
(void)S::prohibit_static_member2;
}

template <typename name, typename Func>
__attribute__((sycl_kernel))
// expected-note@+1 2{{called by}}
void kernel_single_task(Func kernelFunc) { kernelFunc(); }

int main() {
// expected-note@+1 2{{called by}}
kernel_single_task<class fake_kernel>([](){ usage(); } );
return 0;
}
2 changes: 2 additions & 0 deletions clang/test/SemaSYCL/tls_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ void usage() {

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
//expected-note@+1{{called by}}
kernelFunc();
}

int main() {
//expected-note@+1{{called by}}
kernel_single_task<class fake_kernel>([]() { usage(); });
return 0;
}