Skip to content

Commit 45b5267

Browse files
authored
[SYCL] Fix build issue that appeared in self-build (#7881)
1. Define __SYCL_TYPE to empty unless compiling in SYCL device mode 2. Skip sycl_type arguments correctness unless compiling in SYCL device mode
1 parent 29badd8 commit 45b5267

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ def SYCLSpecialClass: InheritableAttr {
13251325
def SYCLType: InheritableAttr {
13261326
let Spellings = [CXX11<"__sycl_detail__", "sycl_type">];
13271327
let Subjects = SubjectList<[CXXRecord, Enum], ErrorDiag>;
1328-
let LangOpts = [SYCLIsDevice, SYCLIsHost];
1328+
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
13291329
let Args = [EnumArgument<"Type", "SYCLType",
13301330
["accessor", "local_accessor", "spec_constant",
13311331
"specialization_id", "kernel_handler", "buffer_location",

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10710,6 +10710,11 @@ void Sema::AddSYCLDeviceHasAttr(Decl *D, const AttributeCommonInfo &CI,
1071010710
}
1071110711

1071210712
static void handleSYCLDeviceHasAttr(Sema &S, Decl *D, const ParsedAttr &A) {
10713+
// Ignore the attribute if compiling for the host side because aspects may not
10714+
// be marked properly for such compilation
10715+
if (!S.Context.getLangOpts().SYCLIsDevice)
10716+
return;
10717+
1071310718
SmallVector<Expr *, 5> Args;
1071410719
for (unsigned I = 0; I < A.getNumArgs(); ++I)
1071510720
Args.push_back(A.getArgAsExpr(I));
@@ -10751,6 +10756,11 @@ void Sema::AddSYCLUsesAspectsAttr(Decl *D, const AttributeCommonInfo &CI,
1075110756
}
1075210757

1075310758
static void handleSYCLUsesAspectsAttr(Sema &S, Decl *D, const ParsedAttr &A) {
10759+
// Ignore the attribute if compiling for the host because aspects may not be
10760+
// marked properly for such compilation
10761+
if (!S.Context.getLangOpts().SYCLIsDevice)
10762+
return;
10763+
1075410764
SmallVector<Expr *, 5> Args;
1075510765
for (unsigned I = 0; I < A.getNumArgs(); ++I)
1075610766
Args.push_back(A.getArgAsExpr(I));

sycl/include/sycl/detail/defines.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@
2121
#endif
2222
#endif
2323

24+
// FIXME Check for __SYCL_DEVICE_ONLY__ can be removed if implementation of
25+
// __has_attribute is fixed to consider LangOpts when generating attributes in
26+
// tablegen.
2427
#if __has_attribute(sycl_special_class) && (defined __SYCL_DEVICE_ONLY__)
2528
#define __SYCL_SPECIAL_CLASS __attribute__((sycl_special_class))
2629
#else
2730
#define __SYCL_SPECIAL_CLASS
2831
#endif
2932

30-
#if __has_cpp_attribute(__sycl_detail__::sycl_type)
33+
// FIXME Check for __SYCL_DEVICE_ONLY__ can be removed if implementation of
34+
// __has_attribute is fixed to consider LangOpts when generating attributes in
35+
// tablegen.
36+
#if __has_cpp_attribute(__sycl_detail__::sycl_type) && \
37+
(defined __SYCL_DEVICE_ONLY__)
3138
#define __SYCL_TYPE(x) [[__sycl_detail__::sycl_type(x)]]
3239
#else
3340
#define __SYCL_TYPE(x)

0 commit comments

Comments
 (0)