Skip to content

Commit 79aa1fc

Browse files
authored
[SYCL] Align TLS diagnosing with community code (#1866)
Move error reporting to the place where OpenMP and CUDA does it. Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent 41424af commit 79aa1fc

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7076,7 +7076,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
70767076
diag::err_thread_non_global)
70777077
<< DeclSpec::getSpecifierName(TSCS);
70787078
else if (!Context.getTargetInfo().isTLSSupported()) {
7079-
if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
7079+
if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
7080+
getLangOpts().SYCLIsDevice) {
70807081
// Postpone error emission until we've collected attributes required to
70817082
// figure out whether it's a host or device variable and whether the
70827083
// error should be ignored.
@@ -7085,14 +7086,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
70857086
// proper storage class for other tools to use even if we're not going
70867087
// to emit any code for it.
70877088
NewVD->setTSCSpec(TSCS);
7088-
} else if (getLangOpts().SYCLIsDevice) {
7089-
// While SYCL does not support TLS, emitting the diagnostic here
7090-
// prevents the compilation of header files with TLS declarations.
7091-
// When TLS objects are used in kernel code, they are diagnosed.
7092-
// We still need to mark the variable as TLS so it shows up in AST with
7093-
// proper storage class for other tools to use even if we're not going
7094-
// to emit any code for it.
7095-
NewVD->setTSCSpec(TSCS);
70967089
} else
70977090
Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
70987091
diag::err_thread_unsupported);
@@ -7102,13 +7095,10 @@ NamedDecl *Sema::ActOnVariableDeclarator(
71027095

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

71137103
switch (D.getDeclSpec().getConstexprSpecifier()) {
71147104
case CSK_unspecified:
@@ -7196,13 +7186,18 @@ NamedDecl *Sema::ActOnVariableDeclarator(
71967186
// Handle attributes prior to checking for duplicates in MergeVarDecl
71977187
ProcessDeclAttributes(S, NewVD, D);
71987188

7199-
if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
7189+
if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
7190+
getLangOpts().SYCLIsDevice) {
72007191
if (EmitTLSUnsupportedError &&
72017192
((getLangOpts().CUDA && DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) ||
72027193
(getLangOpts().OpenMPIsDevice &&
72037194
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(NewVD))))
72047195
Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
72057196
diag::err_thread_unsupported);
7197+
7198+
if (EmitTLSUnsupportedError && getLangOpts().SYCLIsDevice)
7199+
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_thread_unsupported);
7200+
72067201
// CUDA B.2.5: "__shared__ and __constant__ variables have implied static
72077202
// storage [duration]."
72087203
if (SC == SC_None && S->getFnParent() != nullptr &&

clang/test/SemaSYCL/prohibit-thread-local.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -verify -fsyntax-only %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64 -verify -fsyntax-only %s
22

33
thread_local const int prohobit_ns_scope = 0;
44
thread_local int prohobit_ns_scope2 = 0;

0 commit comments

Comments
 (0)