Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,14 @@ def SYCLDevice : InheritableAttr {
let Documentation = [SYCLDeviceDocs];
}

def SYCLGlobalVar : InheritableAttr {
let Spellings = [GNU<"sycl_global_var">];
let Subjects = SubjectList<[GlobalVar]>;
let LangOpts = [SYCLIsDevice];
let Documentation = [Undocumented];
let SimpleHandler = 1;
}

def SYCLKernel : InheritableAttr {
let Spellings = [Clang<"sycl_kernel">];
let Subjects = SubjectList<[FunctionTmpl]>;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
// SYCL device compiler which doesn't produce host binary.
if (LangOpts.SYCLIsDevice) {
Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
Builder.defineMacro("__SYCL_GLOBAL_VAR__", "__attribute__((sycl_global_var))");
Builder.defineMacro("SYCL_EXTERNAL", "__attribute__((sycl_device))");

// Enable __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ macro for
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
if (IsRuntimeEvaluated && !IsConst && VD->getStorageClass() == SC_Static)
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
<< Sema::KernelNonConstStaticDataVariable;
// Non-const globals are allowed for SYCL explicit SIMD.
// Non-const globals are allowed for SYCL explicit SIMD or with the
// SYCLGlobalVar attribute.
else if (IsRuntimeEvaluated && !IsEsimdPrivateGlobal && !IsConst &&
VD->hasGlobalStorage())
VD->hasGlobalStorage() && !VD->hasAttr<SYCLGlobalVarAttr>())
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
<< Sema::KernelGlobalVariable;
// ESIMD globals cannot be used in a SYCL context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
// CHECK-NEXT: ReturnsTwice (SubjectMatchRule_function)
// CHECK-NEXT: SYCLDevice (SubjectMatchRule_function)
// CHECK-NEXT: SYCLDeviceIndirectlyCallable (SubjectMatchRule_function)
// CHECK-NEXT: SYCLGlobalVar (SubjectMatchRule_variable_is_global)
// CHECK-NEXT: SYCLIntelFPGADisableLoopPipelining (SubjectMatchRule_function)
// CHECK-NEXT: SYCLIntelFPGAInitiationInterval (SubjectMatchRule_function)
// CHECK-NEXT: SYCLIntelFPGAMaxConcurrency (SubjectMatchRule_function)
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaSYCL/invalid-kernel-arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class H {
int A;
};

int GlobalNoAttribute;
__attribute__((sycl_global_var)) int GlobalWithAttribute;
__SYCL_GLOBAL_VAR__ int GlobalWithAttributeViaMacro;

int main() {
A Obj{};
D Obj1{};
Expand All @@ -65,6 +69,9 @@ int main() {
(void)Obj4;
(void)Obj5;
(void)Obj6;
(void)GlobalNoAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} expected-note@Inputs/sycl.hpp:* {{called by}}
(void)GlobalWithAttribute;
(void)GlobalWithAttributeViaMacro;
});
return 0;
}