diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 1c5f03f920170..dddbf7454590e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1325,7 +1325,7 @@ def SYCLSpecialClass: InheritableAttr { def SYCLType: InheritableAttr { let Spellings = [CXX11<"__sycl_detail__", "sycl_type">]; let Subjects = SubjectList<[CXXRecord, Enum], ErrorDiag>; - let LangOpts = [SYCLIsDevice, SYCLIsHost]; + let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost]; let Args = [EnumArgument<"Type", "SYCLType", ["accessor", "local_accessor", "spec_constant", "specialization_id", "kernel_handler", "buffer_location", diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5d8710fb682dd..daae13a934e77 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -10710,6 +10710,11 @@ void Sema::AddSYCLDeviceHasAttr(Decl *D, const AttributeCommonInfo &CI, } static void handleSYCLDeviceHasAttr(Sema &S, Decl *D, const ParsedAttr &A) { + // Ignore the attribute if compiling for the host side because aspects may not + // be marked properly for such compilation + if (!S.Context.getLangOpts().SYCLIsDevice) + return; + SmallVector Args; for (unsigned I = 0; I < A.getNumArgs(); ++I) Args.push_back(A.getArgAsExpr(I)); @@ -10751,6 +10756,11 @@ void Sema::AddSYCLUsesAspectsAttr(Decl *D, const AttributeCommonInfo &CI, } static void handleSYCLUsesAspectsAttr(Sema &S, Decl *D, const ParsedAttr &A) { + // Ignore the attribute if compiling for the host because aspects may not be + // marked properly for such compilation + if (!S.Context.getLangOpts().SYCLIsDevice) + return; + SmallVector Args; for (unsigned I = 0; I < A.getNumArgs(); ++I) Args.push_back(A.getArgAsExpr(I)); diff --git a/sycl/include/sycl/detail/defines.hpp b/sycl/include/sycl/detail/defines.hpp index 96fef89592185..b21c6b99615c1 100644 --- a/sycl/include/sycl/detail/defines.hpp +++ b/sycl/include/sycl/detail/defines.hpp @@ -21,13 +21,20 @@ #endif #endif +// FIXME Check for __SYCL_DEVICE_ONLY__ can be removed if implementation of +// __has_attribute is fixed to consider LangOpts when generating attributes in +// tablegen. #if __has_attribute(sycl_special_class) && (defined __SYCL_DEVICE_ONLY__) #define __SYCL_SPECIAL_CLASS __attribute__((sycl_special_class)) #else #define __SYCL_SPECIAL_CLASS #endif -#if __has_cpp_attribute(__sycl_detail__::sycl_type) +// FIXME Check for __SYCL_DEVICE_ONLY__ can be removed if implementation of +// __has_attribute is fixed to consider LangOpts when generating attributes in +// tablegen. +#if __has_cpp_attribute(__sycl_detail__::sycl_type) && \ + (defined __SYCL_DEVICE_ONLY__) #define __SYCL_TYPE(x) [[__sycl_detail__::sycl_type(x)]] #else #define __SYCL_TYPE(x)