From 95beeec9e148a14b54b1074e263ee0b7c8c44771 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Mon, 29 Aug 2022 16:11:18 -0700 Subject: [PATCH 1/6] [SYCL] Replace hardcoded namespaces with attribute Namespaces were hardcoded and used in compiler to check for various SYCL types including accessors, spec_constants, etc. This patch implements an attribute to uniquely identify the types instead. Attribute argument is an Identifier which denotes each type. E.g. __attribute__((sycl_type(accessor)) is used to mark accessor class. The attribite has been implemented as with an accepted list of arguments via EnumArg. The attribute definition should be updated to support any new types. The attribute takes 1 argument. Signed-off-by: Elizabeth Andrews --- clang/include/clang/Basic/Attr.td | 17 ++ clang/include/clang/Sema/Sema.h | 9 +- clang/lib/Sema/SemaDecl.cpp | 2 + clang/lib/Sema/SemaDeclAttr.cpp | 73 ++--- clang/lib/Sema/SemaSYCL.cpp | 269 ++++-------------- clang/test/CodeGenSYCL/Inputs/sycl.hpp | 20 +- .../accessor-readonly-invalid-lib.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + clang/test/SemaSYCL/Inputs/sycl.hpp | 16 +- clang/test/SemaSYCL/sycl-type-attr-ast.cpp | 32 +++ clang/test/SemaSYCL/sycl-type-attr.cpp | 47 +++ sycl/include/sycl/accessor.hpp | 17 +- sycl/include/sycl/aspects.hpp | 2 +- sycl/include/sycl/detail/defines.hpp | 6 + .../ext/oneapi/accessor_property_list.hpp | 3 +- .../ext/oneapi/experimental/spec_constant.hpp | 3 +- sycl/include/sycl/group.hpp | 5 +- sycl/include/sycl/kernel_handler.hpp | 2 +- .../sycl/properties/accessor_properties.hpp | 4 +- sycl/include/sycl/specialization_id.hpp | 2 +- 20 files changed, 242 insertions(+), 290 deletions(-) create mode 100644 clang/test/SemaSYCL/sycl-type-attr-ast.cpp create mode 100644 clang/test/SemaSYCL/sycl-type-attr.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 691b0f3f6922b..40957de19f779 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1281,6 +1281,23 @@ def SYCLSpecialClass: InheritableAttr { let Documentation = [SYCLSpecialClassDocs]; } +def SYCLType: InheritableAttr { + let Spellings = [Clang<"sycl_type">]; + let Subjects = SubjectList<[CXXRecord, Enum], ErrorDiag>; + let LangOpts = [SYCLIsDevice, SYCLIsHost]; + let Args = [EnumArgument<"Type", "SYCLType", + ["accessor", "local_accessor", "spec_constant", + "specialization_id", "kernel_handler", "buffer_location", + "no_alias", "accessor_property_list", "group", + "private_memory", "aspect"], + ["accessor", "local_accessor", "spec_constant", + "specialization_id", "kernel_handler", "buffer_location", + "no_alias", "accessor_property_list", "group", + "private_memory", "aspect"]>]; + // Only used internally by SYCL implementation + let Documentation = [Undocumented]; +} + def SYCLDeviceHas : InheritableAttr { let Spellings = [CXX11<"sycl", "device_has">]; let Subjects = SubjectList<[Function], ErrorDiag>; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 34cf4c7553551..7463cdc5c573d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10855,6 +10855,9 @@ class Sema final { ReqdWorkGroupSizeAttr * MergeReqdWorkGroupSizeAttr(Decl *D, const ReqdWorkGroupSizeAttr &A); + SYCLTypeAttr *MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI, + SYCLTypeAttr::SYCLType TypeName); + /// Only called on function definitions; if there is a MSVC #pragma optimize /// in scope, consider changing the function's attributes based on the /// optimization list passed to the pragma. @@ -13543,12 +13546,16 @@ class Sema final { const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl(); if (!RecTy) return false; + + if (RecTy->hasAttr()) + return true; + if (auto *CTSD = dyn_cast(RecTy)) { ClassTemplateDecl *Template = CTSD->getSpecializedTemplate(); if (CXXRecordDecl *RD = Template->getTemplatedDecl()) return RD->hasAttr(); } - return RecTy->hasAttr(); + return false; } private: diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f337d0f2df173..e38295a2f6d04 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2918,6 +2918,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D, NewAttr = S.MergeSYCLDeviceHasAttr(D, *A); else if (const auto *A = dyn_cast(Attr)) NewAttr = S.MergeSYCLUsesAspectsAttr(D, *A); + else if (const auto *A = dyn_cast(Attr)) + NewAttr = S.MergeSYCLTypeAttr(D, *A, A->getType()); else if (const auto *A = dyn_cast(Attr)) NewAttr = S.MergeSYCLIntelPipeIOAttr(D, *A); else if (const auto *A = dyn_cast(Attr)) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 3e89b474109cd..154a6574a81b1 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -10412,46 +10412,15 @@ static void handleFunctionReturnThunksAttr(Sema &S, Decl *D, D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL)); } -static constexpr std::pair -MakeDeclContextDesc(Decl::Kind K, StringRef SR) { - return std::pair{K, SR}; -} - -// FIXME: Refactor Util class in SemaSYCL.cpp to avoid following -// code duplication. bool isDeviceAspectType(const QualType Ty) { const EnumType *ET = Ty->getAs(); if (!ET) return false; - std::array, 3> Scopes = { - MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - MakeDeclContextDesc(Decl::Kind::Enum, "aspect")}; - - const auto *Ctx = cast(ET->getDecl()); - StringRef Name = ""; - - for (const auto &Scope : llvm::reverse(Scopes)) { - Decl::Kind DK = Ctx->getDeclKind(); - if (DK != Scope.first) - return false; + if (const SYCLTypeAttr *Attr = ET->getDecl()->getAttr()) + return Attr->getType() == SYCLTypeAttr::aspect; - switch (DK) { - case Decl::Kind::Enum: - Name = cast(Ctx)->getName(); - break; - case Decl::Kind::Namespace: - Name = cast(Ctx)->getName(); - break; - default: - llvm_unreachable("isDeviceAspectType: decl kind not supported"); - } - if (Name != Scope.second) - return false; - Ctx = Ctx->getParent(); - } - return Ctx->isTranslationUnit(); + return false; } SYCLDeviceHasAttr *Sema::MergeSYCLDeviceHasAttr(Decl *D, @@ -10576,6 +10545,39 @@ static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { handleSimpleAttribute(S, D, AL); } +SYCLTypeAttr *Sema::MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI, + SYCLTypeAttr::SYCLType TypeName) { + if (const auto ExistingAttr = D->getAttr()) { + if (ExistingAttr->getType() != TypeName) { + Diag(ExistingAttr->getLoc(), diag::warn_duplicate_attribute) + << ExistingAttr; + Diag(CI.getLoc(), diag::note_previous_attribute); + } + // Do not add duplicate attribute + return nullptr; + } + return ::new (Context) SYCLTypeAttr(Context, CI, TypeName); +} + +static void handleSYCLTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { + if (!AL.isArgIdent(0)) { + S.Diag(AL.getLoc(), diag::err_attribute_argument_type) + << AL << AANT_ArgumentIdentifier; + return; + } + + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + SYCLTypeAttr::SYCLType Type; + + if (!SYCLTypeAttr::ConvertStrToSYCLType(II->getName(), Type)) { + S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; + return; + } + + if (SYCLTypeAttr *NewAttr = S.MergeSYCLTypeAttr(D, AL, Type)) + D->addAttr(NewAttr); +} + static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) { if (!cast(D)->hasGlobalStorage()) { S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var) @@ -11128,6 +11130,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_SYCLSpecialClass: handleSimpleAttribute(S, D, AL); break; + case ParsedAttr::AT_SYCLType: + handleSYCLTypeAttr(S, D, AL); + break; case ParsedAttr::AT_SYCLDevice: handleSYCLDeviceAttr(S, D, AL); break; diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index e6a8b976de883..95a2e03554a2e 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -67,79 +67,36 @@ static constexpr llvm::StringLiteral LibstdcxxFailedAssertion = "__failed_assertion"; constexpr unsigned MaxKernelArgsSize = 2048; -namespace { +static bool isSyclType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) { + const auto *RD = Ty->getAsCXXRecordDecl(); + if (!RD) + return false; -/// Various utilities. -class Util { -public: - using DeclContextDesc = std::pair; - - template - static constexpr DeclContextDesc MakeDeclContextDesc(Decl::Kind K, - const char (&Str)[N]) { - // FIXME: This SHOULD be able to use the StringLiteral constructor here - // instead, however this seems to fail with an 'invalid string literal' note - // on the correct constructor in some build configurations. We need to - // figure that out before reverting this to use the StringLiteral - // constructor. - return DeclContextDesc{K, StringRef{Str, N - 1}}; - } - - static constexpr DeclContextDesc MakeDeclContextDesc(Decl::Kind K, - StringRef SR) { - return DeclContextDesc{K, SR}; - } - - static bool isSyclSpecialType(QualType Ty); - - /// Checks whether given clang type is a full specialization of the SYCL - /// accessor_property_list class. - static bool isAccessorPropertyListType(QualType Ty); - - /// Checks whether given clang type is a full specialization of the SYCL - /// no_alias class. - static bool isSyclAccessorNoAliasPropertyType(QualType Ty); - - /// Checks whether given clang type is a full specialization of the SYCL - /// buffer_location class. - static bool isSyclBufferLocationType(QualType Ty); - - /// Checks whether given clang type is a standard SYCL API class with given - /// name. - /// \param Ty the clang type being checked - /// \param Name the class name checked against - /// \param Tmpl whether the class is template instantiation or simple record - static bool isSyclType(QualType Ty, StringRef Name, bool Tmpl = false); - - /// Checks whether given clang type is a full specialization of the SYCL - /// specialization constant class. - static bool isSyclSpecConstantType(QualType Ty); - - /// Checks whether given clang type is a full specialization of the SYCL - /// specialization id class. - static bool isSyclSpecIdType(QualType Ty); - - /// Checks whether given clang type is a full specialization of the SYCL - /// kernel_handler class. - static bool isSyclKernelHandlerType(QualType Ty); - - // Checks declaration context hierarchy. - /// \param DC the context of the item to be checked. - /// \param Scopes the declaration scopes leading from the item context to the - /// translation unit (excluding the latter) - static bool matchContext(const DeclContext *DC, - ArrayRef Scopes); - - /// Checks whether given clang type is declared in the given hierarchy of - /// declaration contexts. - /// \param Ty the clang type being checked - /// \param Scopes the declaration scopes leading from the type to the - /// translation unit (excluding the latter) - static bool matchQualifiedTypeName(QualType Ty, - ArrayRef Scopes); -}; + if (const SYCLTypeAttr *Attr = RD->getAttr()) + return Attr->getType() == TypeName; + + if (const auto *CTSD = dyn_cast(RD)) + if (CXXRecordDecl *TemplateDecl = + CTSD->getSpecializedTemplate()->getTemplatedDecl()) + if (const SYCLTypeAttr *Attr = TemplateDecl->getAttr()) + return Attr->getType() == TypeName; -} // anonymous namespace + return false; +} + +// FIXME: Accessor property lists should be modified to use compile-time +// properties. Once implemented, this function (and possibly all/most code +// in SemaSYCL.cpp handling no_alias and buffer_location property) can be +// removed. +static bool isAccessorPropertyType(QualType Ty, + SYCLTypeAttr::SYCLType TypeName) { + if (const auto *RD = Ty->getAsCXXRecordDecl()) + if (const auto *Parent = dyn_cast(RD->getParent())) + if (const SYCLTypeAttr *Attr = Parent->getAttr()) + return Attr->getType() == TypeName; + + return false; +} ExprResult Sema::ActOnSYCLBuiltinNumFieldsExpr(ParsedType PT) { TypeSourceInfo *TInfo = nullptr; @@ -924,7 +881,7 @@ class MarkWIScopeFnVisitor : public RecursiveASTVisitor { // not a direct call - continue search return true; QualType Ty = Ctx.getRecordType(Call->getRecordDecl()); - if (!Util::isSyclType(Ty, "group", true /*Tmpl*/)) + if (!isSyclType(Ty, SYCLTypeAttr::group)) // not a member of sycl::group - continue search return true; auto Name = Callee->getName(); @@ -944,7 +901,7 @@ class MarkWIScopeFnVisitor : public RecursiveASTVisitor { }; static bool isSYCLPrivateMemoryVar(VarDecl *VD) { - return Util::isSyclType(VD->getType(), "private_memory", true /*Tmpl*/); + return isSyclType(VD->getType(), SYCLTypeAttr::private_memory); } static void addScopeAttrToLocalVars(CXXMethodDecl &F) { @@ -1064,7 +1021,7 @@ static ParmVarDecl *getSyclKernelHandlerArg(FunctionDecl *KernelCallerFunc) { // Specialization constants in SYCL 2020 are not captured by lambda and // accessed through new optional lambda argument kernel_handler auto IsHandlerLambda = [](ParmVarDecl *PVD) { - return Util::isSyclKernelHandlerType(PVD->getType()); + return isSyclType(PVD->getType(), SYCLTypeAttr::kernel_handler); }; assert(llvm::count_if(KernelCallerFunc->parameters(), IsHandlerLambda) <= 1 && @@ -1186,7 +1143,8 @@ class KernelObjVisitor { for (const auto &Base : Range) { QualType BaseTy = Base.getType(); // Handle accessor class as base - if (Util::isSyclSpecialType(BaseTy)) { + if (SemaRef.isTypeDecoratedWithDeclAttribute( + BaseTy)) { (void)std::initializer_list{ (Handlers.handleSyclSpecialType(Owner, Base, BaseTy), 0)...}; } else @@ -1268,9 +1226,9 @@ class KernelObjVisitor { template void visitField(const CXXRecordDecl *Owner, FieldDecl *Field, QualType FieldTy, HandlerTys &... Handlers) { - if (Util::isSyclSpecialType(FieldTy)) + if (SemaRef.isTypeDecoratedWithDeclAttribute(FieldTy)) KF_FOR_EACH(handleSyclSpecialType, Field, FieldTy); - else if (Util::isSyclSpecConstantType(FieldTy)) + else if (isSyclType(FieldTy, SYCLTypeAttr::spec_constant)) KF_FOR_EACH(handleSyclSpecConstantType, Field, FieldTy); else if (FieldTy->isStructureOrClassType()) { if (KF_FOR_EACH(handleStructType, Field, FieldTy)) { @@ -1553,7 +1511,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler { Loc, diag::err_sycl_invalid_accessor_property_template_param); QualType PropListTy = PropList.getAsType(); - if (!Util::isAccessorPropertyListType(PropListTy)) + if (!isSyclType(PropListTy, SYCLTypeAttr::accessor_property_list)) return SemaRef.Diag( Loc, diag::err_sycl_invalid_accessor_property_template_param); @@ -1579,7 +1537,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler { diag::err_sycl_invalid_accessor_property_list_template_param) << /*accessor_property_list pack argument*/ 1 << /*type*/ 1; QualType PropTy = Prop->getAsType(); - if (Util::isSyclBufferLocationType(PropTy) && + if (isAccessorPropertyType(PropTy, SYCLTypeAttr::buffer_location) && checkBufferLocationType(PropTy, Loc)) return true; } @@ -1612,10 +1570,10 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler { } bool checkSyclSpecialType(QualType Ty, SourceRange Loc) { - assert(Util::isSyclSpecialType(Ty) && + assert(SemaRef.isTypeDecoratedWithDeclAttribute(Ty) && "Should only be called on sycl special class types."); const RecordDecl *RecD = Ty->getAsRecordDecl(); - if (IsSIMD && !Util::isSyclType(Ty, "accessor", true /*Tmp*/)) + if (IsSIMD && !isSyclType(Ty, SYCLTypeAttr::accessor)) return SemaRef.Diag(Loc.getBegin(), diag::err_sycl_esimd_not_supported_for_type) << RecD; @@ -1893,9 +1851,9 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { for (TemplateArgument::pack_iterator Prop = TemplArg.pack_begin(); Prop != TemplArg.pack_end(); ++Prop) { QualType PropTy = Prop->getAsType(); - if (Util::isSyclAccessorNoAliasPropertyType(PropTy)) + if (isAccessorPropertyType(PropTy, SYCLTypeAttr::no_alias)) handleNoAliasProperty(Param, PropTy, Loc); - if (Util::isSyclBufferLocationType(PropTy)) + if (isAccessorPropertyType(PropTy, SYCLTypeAttr::buffer_location)) handleBufferLocationProperty(Param, PropTy, Loc); } } @@ -1953,7 +1911,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { assert(RecordDecl && "The type must be a RecordDecl"); llvm::StringLiteral MethodName = KernelDecl->hasAttr() && - Util::isSyclType(FieldTy, "accessor", true /*Tmp*/) + isSyclType(FieldTy, SYCLTypeAttr::accessor) ? InitESIMDMethodName : InitMethodName; CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName); @@ -1978,7 +1936,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { // added, this code needs to be refactored to call // handleAccessorPropertyList for each class which requires it. if (ParamTy.getTypePtr()->isPointerType() && - Util::isSyclType(FieldTy, "accessor", true /*Tmp*/)) + isSyclType(FieldTy, SYCLTypeAttr::accessor)) handleAccessorType(RecordDecl, FD->getBeginLoc()); } LastParamIndex = ParamIndex; @@ -2074,7 +2032,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { assert(RecordDecl && "The type must be a RecordDecl"); llvm::StringLiteral MethodName = KernelDecl->hasAttr() && - Util::isSyclType(FieldTy, "accessor", true /*Tmp*/) + isSyclType(FieldTy, SYCLTypeAttr::accessor) ? InitESIMDMethodName : InitMethodName; CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName); @@ -2093,7 +2051,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { // added, this code needs to be refactored to call // handleAccessorPropertyList for each class which requires it. if (ParamTy.getTypePtr()->isPointerType() && - Util::isSyclType(FieldTy, "accessor", true /*Tmp*/)) + isSyclType(FieldTy, SYCLTypeAttr::accessor)) handleAccessorType(RecordDecl, BS.getBeginLoc()); } LastParamIndex = ParamIndex; @@ -2215,7 +2173,7 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler { const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl(); assert(RecordDecl && "The type must be a RecordDecl"); llvm::StringLiteral MethodName = - (IsSIMD && Util::isSyclType(FieldTy, "accessor", true /*Tmp*/)) + (IsSIMD && isSyclType(FieldTy, SYCLTypeAttr::accessor)) ? InitESIMDMethodName : InitMethodName; CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName); @@ -3134,7 +3092,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { bool handleSyclSpecialType(FieldDecl *FD, QualType FieldTy) final { const auto *ClassTy = FieldTy->getAsCXXRecordDecl(); assert(ClassTy && "Type must be a C++ record type"); - if (Util::isSyclType(FieldTy, "accessor", true /*Tmp*/)) { + if (isSyclType(FieldTy, SYCLTypeAttr::accessor)) { const auto *AccTy = cast(FieldTy->getAsRecordDecl()); assert(AccTy->getTemplateArgs().size() >= 2 && @@ -4861,7 +4819,7 @@ void SYCLIntegrationFooter::addVarDecl(const VarDecl *VD) { if (isa(VD)) return; // Step 1: ensure that this is of the correct type template specialization. - if (!Util::isSyclSpecIdType(VD->getType()) && + if (!isSyclType(VD->getType(), SYCLTypeAttr::specialization_id) && !S.isTypeDecoratedWithDeclAttribute( VD->getType())) { // Handle the case where this could be a deduced type, such as a deduction @@ -5043,7 +5001,7 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) { // Skip if this isn't a SpecIdType or DeviceGlobal. This can happen if it // was a deduced type. - if (!Util::isSyclSpecIdType(VD->getType()) && + if (!isSyclType(VD->getType(), SYCLTypeAttr::specialization_id) && !S.isTypeDecoratedWithDeclAttribute( VD->getType())) continue; @@ -5119,132 +5077,3 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) { } return true; } - -// ----------------------------------------------------------------------------- -// Utility class methods -// ----------------------------------------------------------------------------- -bool Util::isSyclSpecialType(const QualType Ty) { - const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl(); - if (!RecTy) - return false; - return RecTy->hasAttr(); -} - -bool Util::isSyclSpecConstantType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ext"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "oneapi"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "experimental"), - Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization, - "spec_constant")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isSyclSpecIdType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(clang::Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization, - "specialization_id")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isSyclKernelHandlerType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "kernel_handler")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isSyclAccessorNoAliasPropertyType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ext"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "oneapi"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "property"), - Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "no_alias"), - Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization, - "instance")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isSyclBufferLocationType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ext"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "intel"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "property"), - Util::MakeDeclContextDesc(Decl::Kind::CXXRecord, "buffer_location"), - Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization, - "instance")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isSyclType(QualType Ty, StringRef Name, bool Tmpl) { - Decl::Kind ClassDeclKind = - Tmpl ? Decl::Kind::ClassTemplateSpecialization : Decl::Kind::CXXRecord; - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(ClassDeclKind, Name)}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::isAccessorPropertyListType(QualType Ty) { - std::array Scopes = { - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "ext"), - Util::MakeDeclContextDesc(Decl::Kind::Namespace, "oneapi"), - Util::MakeDeclContextDesc(Decl::Kind::ClassTemplateSpecialization, - "accessor_property_list")}; - return matchQualifiedTypeName(Ty, Scopes); -} - -bool Util::matchContext(const DeclContext *Ctx, - ArrayRef Scopes) { - // The idea: check the declaration context chain starting from the item - // itself. At each step check the context is of expected kind - // (namespace) and name. - StringRef Name = ""; - - for (const auto &Scope : llvm::reverse(Scopes)) { - Decl::Kind DK = Ctx->getDeclKind(); - if (DK != Scope.first) - return false; - - switch (DK) { - case Decl::Kind::ClassTemplateSpecialization: - // ClassTemplateSpecializationDecl inherits from CXXRecordDecl - case Decl::Kind::CXXRecord: - Name = cast(Ctx)->getName(); - break; - case Decl::Kind::Namespace: - Name = cast(Ctx)->getName(); - break; - default: - llvm_unreachable("matchContext: decl kind not supported"); - } - if (Name != Scope.second) - return false; - Ctx = Ctx->getParent(); - } - return Ctx->isTranslationUnit() || - (Ctx->isExternCXXContext() && - Ctx->getEnclosingNamespaceContext()->isTranslationUnit()); -} - -bool Util::matchQualifiedTypeName(QualType Ty, - ArrayRef Scopes) { - const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl(); - - if (!RecTy) - return false; // only classes/structs supported - const auto *Ctx = cast(RecTy); - return Util::matchContext(Ctx, Scopes); -} diff --git a/clang/test/CodeGenSYCL/Inputs/sycl.hpp b/clang/test/CodeGenSYCL/Inputs/sycl.hpp index f9ca128301f39..411930419a67c 100644 --- a/clang/test/CodeGenSYCL/Inputs/sycl.hpp +++ b/clang/test/CodeGenSYCL/Inputs/sycl.hpp @@ -29,7 +29,7 @@ class __attribute__((sycl_special_class)) sampler { }; template -class group { +class __attribute__((sycl_type(group))) group { public: group() = default; // fake constructor }; @@ -69,7 +69,7 @@ enum class address_space : int { } // namespace access // Dummy aspect enum with limited enumerators -enum class aspect { +enum class __attribute__((sycl_type(aspect))) aspect { host = 0, cpu = 1, gpu = 2, @@ -119,7 +119,7 @@ namespace ext { namespace intel { namespace property { // Compile time known accessor property -struct buffer_location { +struct __attribute__((sycl_type(buffer_location))) buffer_location { template class instance {}; }; } // namespace property @@ -130,7 +130,7 @@ namespace ext { namespace oneapi { namespace property { // Compile time known accessor property -struct no_alias { +struct __attribute__((sycl_type(no_alias))) no_alias { template class instance {}; }; } // namespace property @@ -172,7 +172,7 @@ template struct item { namespace ext { namespace oneapi { template -class accessor_property_list {}; +class __attribute__((sycl_type(accessor_property_list))) accessor_property_list {}; } // namespace oneapi } // namespace ext @@ -201,7 +201,7 @@ template > -class __attribute__((sycl_special_class)) accessor { +class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { public: void use(void) const {} @@ -267,7 +267,7 @@ struct _ImageImplT { }; template -class __attribute__((sycl_special_class)) accessor { +class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { public: void use(void) const {} template @@ -324,7 +324,7 @@ namespace ext { namespace oneapi { namespace experimental { template -class spec_constant { +class __attribute__((sycl_type(spec_constant))) spec_constant { public: spec_constant() {} spec_constant(T Cst) {} @@ -355,11 +355,11 @@ int printf(const __SYCL_CONSTANT_AS char *__format, Args... args) { } // namespace oneapi } // namespace ext -class kernel_handler { +class __attribute__((sycl_type(kernel_handler))) kernel_handler { void __init_specialization_constants_buffer(char *specialization_constants_buffer) {} }; -template class specialization_id { +template class __attribute__((sycl_type(specialization_id))) specialization_id { public: using value_type = T; diff --git a/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp b/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp index 2ca60450d5c56..da9756916848b 100644 --- a/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp +++ b/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp @@ -60,7 +60,7 @@ struct _ImplT { template -class __attribute__((sycl_special_class)) accessor { +class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { public: void use(void) const {} diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test index 99855ca0dd395..8c1314d247ac0 100644 --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -184,6 +184,7 @@ // CHECK-NEXT: SYCLRegisterNum (SubjectMatchRule_variable_is_global) // CHECK-NEXT: SYCLSimd (SubjectMatchRule_function, SubjectMatchRule_variable_is_global) // CHECK-NEXT: SYCLSpecialClass (SubjectMatchRule_record) +// CHECK-NEXT: SYCLType (SubjectMatchRule_record, SubjectMatchRule_enum) // CHECK-NEXT: SYCLUsesAspects (SubjectMatchRule_record, SubjectMatchRule_function) // CHECK-NEXT: ScopedLockable (SubjectMatchRule_record) // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property) diff --git a/clang/test/SemaSYCL/Inputs/sycl.hpp b/clang/test/SemaSYCL/Inputs/sycl.hpp index e1b3c19e5f70c..bc4a9bfe60a0a 100644 --- a/clang/test/SemaSYCL/Inputs/sycl.hpp +++ b/clang/test/SemaSYCL/Inputs/sycl.hpp @@ -39,7 +39,7 @@ enum class address_space : int { } // namespace access // Dummy aspect enum with limited enumerators -enum class aspect { +enum class __attribute__((sycl_type(aspect))) aspect { host = 0, cpu = 1, gpu = 2, @@ -54,7 +54,7 @@ class property_list {}; namespace ext { namespace intel { namespace property { -struct buffer_location { +struct __attribute__((sycl_type(buffer_location))) buffer_location { template class instance {}; }; } // namespace property @@ -64,7 +64,7 @@ struct buffer_location { namespace ext { namespace oneapi { template -class accessor_property_list {}; +class __attribute__((sycl_type(accessor_property_list))) accessor_property_list {}; // device_global type decorated with attributes template @@ -131,7 +131,7 @@ template > -class __attribute__((sycl_special_class)) accessor { +class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { public: void use(void) const {} void use(void *) const {} @@ -194,7 +194,7 @@ struct _ImageImplT { }; template -class __attribute__((sycl_special_class)) accessor { +class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { public: void use(void) const {} template @@ -240,12 +240,12 @@ struct get_kernel_name_t { }; template -class group { +class __attribute__((sycl_type(group))) group { public: group() = default; // fake constructor }; -class kernel_handler { +class __attribute__((sycl_type(kernel_handler))) kernel_handler { void __init_specialization_constants_buffer(char *specialization_constants_buffer) {} }; @@ -373,7 +373,7 @@ namespace ext { namespace oneapi { namespace experimental { template -class spec_constant { +class __attribute__((sycl_type(spec_constant))) spec_constant { public: spec_constant() {} explicit constexpr spec_constant(T defaultVal) : DefaultValue(defaultVal) {} diff --git a/clang/test/SemaSYCL/sycl-type-attr-ast.cpp b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp new file mode 100644 index 0000000000000..d9dc48ac630be --- /dev/null +++ b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -ast-dump %s | FileCheck %s + +// Tests for AST of sycl_type() attribute + +class __attribute__((sycl_type(accessor))) accessor {}; +// CHECK: CXXRecordDecl {{.*}} class accessor definition +// CHECK: SYCLTypeAttr {{.*}} accessor + +class accessor; +// CHECK: CXXRecordDecl {{.*}} prev {{.*}} class accessor +// CHECK: SYCLTypeAttr {{.*}} Inherited accessor + +enum class __attribute__((sycl_type(aspect))) aspect {}; +// CHECK: EnumDecl {{.*}} class aspect 'int' +// CHECK: SYCLTypeAttr {{.*}} aspect + +template +class __attribute__((sycl_type(local_accessor))) local_accessor {}; +// CHECK: ClassTemplateDecl {{.*}} local_accessor +// CHECK: CXXRecordDecl {{.*}} class local_accessor definition +// CHECK: SYCLTypeAttr {{.*}} local_accessor + +class __attribute__((sycl_type(spec_constant))) __attribute__((sycl_type(spec_constant))) spec_constant; +// CHECK: CXXRecordDecl {{.*}} spec_constant +// CHECK: SYCLTypeAttr {{.*}} spec_constant +// CHECK-NOT: SYCLTypeAttr {{.*}} spec_constant + +template <> +class __attribute__((sycl_type(local_accessor))) local_accessor {}; +// CHECK: ClassTemplateSpecializationDecl {{.*}} class local_accessor definition +// CHECK: SYCLTypeAttr {{.*}} local_accessor + diff --git a/clang/test/SemaSYCL/sycl-type-attr.cpp b/clang/test/SemaSYCL/sycl-type-attr.cpp new file mode 100644 index 0000000000000..0f9b57c3bdc63 --- /dev/null +++ b/clang/test/SemaSYCL/sycl-type-attr.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -verify %s + +// Diagnostic tests for sycl_type() attribute + +#include "sycl.hpp" + +// expected-error@+1{{'sycl_type' attribute only applies to classes}} +__attribute__((sycl_type(accessor))) int a; + +// expected-error@+1{{'sycl_type' attribute only applies to classes}} +__attribute__((sycl_type(accessor))) void func1() {} + +// expected-error@+1{{'sycl_type' attribute requires an identifier}} +class __attribute__((sycl_type("accessor"))) A {}; + +// expected-error@+1{{'sycl_type' attribute takes one argument}} +class __attribute__((sycl_type())) B {}; + +// expected-warning@+1{{'sycl_type' attribute argument not supported: 'NotValidType'}} +class __attribute__((sycl_type(NotValidType))) C {}; + +// expected-note@+1{{previous attribute is here}} +class __attribute__((sycl_type(spec_constant))) spec_constant; +// expected-warning@+1{{attribute 'sycl_type' is already applied with different arguments}} +class __attribute__((sycl_type(accessor))) spec_constant {}; + +// expected-warning@+2{{attribute 'sycl_type' is already applied with different arguments}} +// expected-note@+1{{previous attribute is here}} +class __attribute__((sycl_type(group))) __attribute__((sycl_type(accessor))) group {}; + +// Valid usage - + +class __attribute__((sycl_type(accessor))) accessor {}; + +template +class __attribute__((sycl_type(local_accessor))) local_accessor {}; + +enum class __attribute__((sycl_type(aspect))) aspect {}; + +// No diagnostic for matching arguments. +class __attribute__((sycl_type(kernel_handler))) kernel_handler; +class __attribute__((sycl_type(kernel_handler))) __attribute__((sycl_type(kernel_handler))) kernel_handler {}; +class kernel_handler; + + + + diff --git a/sycl/include/sycl/accessor.hpp b/sycl/include/sycl/accessor.hpp index 0fd532bebcd57..459ae19e62af1 100644 --- a/sycl/include/sycl/accessor.hpp +++ b/sycl/include/sycl/accessor.hpp @@ -786,7 +786,7 @@ class __image_array_slice__ { template -class __SYCL_SPECIAL_CLASS accessor : +class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : #ifndef __SYCL_DEVICE_ONLY__ public detail::AccessorBaseHost, #endif @@ -2016,8 +2016,9 @@ accessor(buffer, handler, Type1, Type2, Type3, /// \ingroup sycl_api_acc template -class __SYCL_SPECIAL_CLASS accessor : +class __SYCL_SPECIAL_CLASS +__SYCL_TYPE(accessor) accessor : #ifndef __SYCL_DEVICE_ONLY__ public detail::LocalAccessorBaseHost, #endif @@ -2226,8 +2227,9 @@ class __SYCL_SPECIAL_CLASS accessor -class __SYCL_SPECIAL_CLASS accessor +class __SYCL_SPECIAL_CLASS +__SYCL_TYPE(accessor) accessor : public detail::image_accessor { public: @@ -2316,8 +2318,9 @@ class accessor -class __SYCL_SPECIAL_CLASS accessor +class __SYCL_SPECIAL_CLASS +__SYCL_TYPE(accessor) accessor : public detail::image_accessor { #ifdef __SYCL_DEVICE_ONLY__ diff --git a/sycl/include/sycl/aspects.hpp b/sycl/include/sycl/aspects.hpp index d71a903ac916b..ed7957f96e14b 100644 --- a/sycl/include/sycl/aspects.hpp +++ b/sycl/include/sycl/aspects.hpp @@ -12,7 +12,7 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { -enum class aspect { +enum class __SYCL_TYPE(aspect) aspect { host = 0, cpu = 1, gpu = 2, diff --git a/sycl/include/sycl/detail/defines.hpp b/sycl/include/sycl/detail/defines.hpp index 40cf18c953178..d80dd2c2a8504 100644 --- a/sycl/include/sycl/detail/defines.hpp +++ b/sycl/include/sycl/detail/defines.hpp @@ -26,3 +26,9 @@ #else #define __SYCL_SPECIAL_CLASS #endif + +#if __has_attribute(sycl_type) +#define __SYCL_TYPE(x) __attribute__((sycl_type(x))) +#else +#define __SYCL_TYPE(x) +#endif diff --git a/sycl/include/sycl/ext/oneapi/accessor_property_list.hpp b/sycl/include/sycl/ext/oneapi/accessor_property_list.hpp index 85734bc34ebe3..305d5122577c2 100644 --- a/sycl/include/sycl/ext/oneapi/accessor_property_list.hpp +++ b/sycl/include/sycl/ext/oneapi/accessor_property_list.hpp @@ -40,7 +40,8 @@ template struct is_compile_time_property : std::false_type {}; /// /// \ingroup sycl_api template -class accessor_property_list : protected sycl::detail::PropertyListBase { +class __SYCL_TYPE(accessor_property_list) accessor_property_list + : protected sycl::detail::PropertyListBase { // These structures check if compile-time-constant property is present in // list. For runtime properties this check is always true. template struct AreSameTemplate : std::is_same {}; diff --git a/sycl/include/sycl/ext/oneapi/experimental/spec_constant.hpp b/sycl/include/sycl/ext/oneapi/experimental/spec_constant.hpp index e587cd4cb5bff..dd7a4ff9becd2 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/spec_constant.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/spec_constant.hpp @@ -34,7 +34,8 @@ class spec_const_error : public compile_program_error { template class __SYCL2020_DEPRECATED( "Specialization constats extension is deprecated, use SYCL 2020" - " specialization constants instead") spec_constant { + " specialization constants instead") + __SYCL_TYPE(spec_constant) spec_constant { public: spec_constant() {} diff --git a/sycl/include/sycl/group.hpp b/sycl/include/sycl/group.hpp index 0f65326419bd2..fb2e0b5f491a7 100644 --- a/sycl/include/sycl/group.hpp +++ b/sycl/include/sycl/group.hpp @@ -49,7 +49,8 @@ static inline void workGroupBarrier() { // class can be used to wrap the data. This class very simply constructs // private data for a given group across the entire group.The id of the // current work-item is passed to any access to grab the correct data. -template class private_memory { +template +class __SYCL_TYPE(private_memory) private_memory { public: // Construct based directly off the number of work-items private_memory(const group &G) { @@ -90,7 +91,7 @@ template class private_memory { /// within a parallel execution. /// /// \ingroup sycl_api -template class group { +template class __SYCL_TYPE(group) group { public: #ifndef __DISABLE_SYCL_INTEL_GROUP_ALGORITHMS__ using id_type = id; diff --git a/sycl/include/sycl/kernel_handler.hpp b/sycl/include/sycl/kernel_handler.hpp index f80fd6df8405d..e37888e44d34c 100644 --- a/sycl/include/sycl/kernel_handler.hpp +++ b/sycl/include/sycl/kernel_handler.hpp @@ -19,7 +19,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { /// Reading the value of a specialization constant /// /// \ingroup sycl_api -class kernel_handler { +class __SYCL_TYPE(kernel_handler) kernel_handler { public: #if __cplusplus >= 201703L template diff --git a/sycl/include/sycl/properties/accessor_properties.hpp b/sycl/include/sycl/properties/accessor_properties.hpp index cb721d4d1f079..5b5832bb51f02 100644 --- a/sycl/include/sycl/properties/accessor_properties.hpp +++ b/sycl/include/sycl/properties/accessor_properties.hpp @@ -48,7 +48,7 @@ constexpr const auto &noinit __SYCL2020_DEPRECATED("spelling is now: no_init") = namespace ext { namespace intel { namespace property { -struct buffer_location { +struct __SYCL_TYPE(buffer_location) buffer_location { template struct instance { template constexpr bool operator==(const buffer_location::instance &) const { @@ -82,7 +82,7 @@ struct no_offset { } }; }; -struct no_alias { +struct __SYCL_TYPE(no_alias) no_alias { template struct instance { constexpr bool operator==(const no_alias::instance &) const { return true; diff --git a/sycl/include/sycl/specialization_id.hpp b/sycl/include/sycl/specialization_id.hpp index 8a94d324f6a6c..8570becba9e49 100644 --- a/sycl/include/sycl/specialization_id.hpp +++ b/sycl/include/sycl/specialization_id.hpp @@ -14,7 +14,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { /// Declaring a specialization constant /// /// \ingroup sycl_api -template class specialization_id { +template class __SYCL_TYPE(specialization_id) specialization_id { public: using value_type = T; From 839c3ff4315b86a765b6fe0a34b0075332e20126 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Tue, 30 Aug 2022 14:40:30 -0700 Subject: [PATCH 2/6] [SYCL] Add changes for local_accessor Signed-off-by: Elizabeth Andrews --- clang/lib/Sema/SemaSYCL.cpp | 6 +++--- clang/test/CodeGenSYCL/Inputs/sycl.hpp | 2 +- clang/test/SemaSYCL/Inputs/sycl.hpp | 2 +- sycl/include/sycl/accessor.hpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 158b21bc61700..89db97b2e5d51 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -84,7 +84,7 @@ static bool isSyclType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) { return false; } -static isSyclAccessorType(QualType Ty) { +static bool isSyclAccessorType(QualType Ty) { return isSyclType(Ty, SYCLTypeAttr::accessor) || isSyclType(Ty, SYCLTypeAttr::local_accessor); } @@ -985,7 +985,7 @@ static ParamDesc makeParamDesc(ASTContext &Ctx, StringRef Name, QualType Ty) { /// \return the target of given SYCL accessor type static target getAccessTarget(QualType FieldTy, const ClassTemplateSpecializationDecl *AccTy) { - if (Util::isSyclType(FieldTy, SYCLTypeAttr::local_accessor)) + if (isSyclType(FieldTy, SYCLTypeAttr::local_accessor)) return local; return static_cast( @@ -1899,7 +1899,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler { handleAccessorPropertyList(Params.back(), RecordDecl, Loc); // If "accessor" type check if read only - if (Util::isSyclType(FieldTy, SYCLTypeAttr::accessor)) { + if (isSyclType(FieldTy, SYCLTypeAttr::accessor)) { // Get access mode of accessor. const auto *AccessorSpecializationDecl = cast(RecordDecl); diff --git a/clang/test/CodeGenSYCL/Inputs/sycl.hpp b/clang/test/CodeGenSYCL/Inputs/sycl.hpp index 0f21c2d0aa66e..35c8ad4f83153 100644 --- a/clang/test/CodeGenSYCL/Inputs/sycl.hpp +++ b/clang/test/CodeGenSYCL/Inputs/sycl.hpp @@ -292,7 +292,7 @@ class accessor -class __attribute__((sycl_special_class)) +class __attribute__((sycl_special_class)) __attribute__((sycl_type(local_accessor))) local_accessor: public accessor { diff --git a/clang/test/SemaSYCL/Inputs/sycl.hpp b/clang/test/SemaSYCL/Inputs/sycl.hpp index 7880f13f5f27a..50079ba2be8d0 100644 --- a/clang/test/SemaSYCL/Inputs/sycl.hpp +++ b/clang/test/SemaSYCL/Inputs/sycl.hpp @@ -208,7 +208,7 @@ class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) }; template -class __attribute__((sycl_special_class)) +class __attribute__((sycl_special_class)) __attribute__((sycl_type(local_accessor))) local_accessor: public accessor { diff --git a/sycl/include/sycl/accessor.hpp b/sycl/include/sycl/accessor.hpp index c1c1d8615e4fb..2ae84070fd3a1 100644 --- a/sycl/include/sycl/accessor.hpp +++ b/sycl/include/sycl/accessor.hpp @@ -2313,7 +2313,7 @@ class __SYCL_SPECIAL_CLASS accessor -class __SYCL_SPECIAL_CLASS local_accessor +class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor : public local_accessor_base { From d4e97ab7fa51045bafef7c54a20faa59938ae8d6 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Wed, 31 Aug 2022 23:24:55 -0700 Subject: [PATCH 3/6] Apply review comments Signed-off-by: Elizabeth Andrews --- clang/include/clang/Basic/Attr.td | 4 +-- .../clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaDeclAttr.cpp | 4 +-- clang/lib/Sema/SemaSYCL.cpp | 13 +++++--- clang/test/CodeGenSYCL/Inputs/sycl.hpp | 23 ++++++------- .../accessor-readonly-invalid-lib.cpp | 2 +- clang/test/SemaSYCL/Inputs/sycl.hpp | 20 ++++++----- clang/test/SemaSYCL/sycl-type-attr-ast.cpp | 11 ++++--- clang/test/SemaSYCL/sycl-type-attr.cpp | 33 ++++++++++--------- sycl/include/sycl/detail/defines.hpp | 4 +-- 10 files changed, 63 insertions(+), 53 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 6b9b39bca1323..7e7b41dde9391 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1282,7 +1282,7 @@ def SYCLSpecialClass: InheritableAttr { } def SYCLType: InheritableAttr { - let Spellings = [Clang<"sycl_type">]; + let Spellings = [CXX11<"__sycl_detail__", "sycl_type">]; let Subjects = SubjectList<[CXXRecord, Enum], ErrorDiag>; let LangOpts = [SYCLIsDevice, SYCLIsHost]; let Args = [EnumArgument<"Type", "SYCLType", @@ -1295,7 +1295,7 @@ def SYCLType: InheritableAttr { "no_alias", "accessor_property_list", "group", "private_memory", "aspect"]>]; // Only used internally by SYCL implementation - let Documentation = [Undocumented]; + let Documentation = [InternalOnly]; } def SYCLDeviceHas : InheritableAttr { diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d87176ec939c8..7c397c9b7245f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4098,6 +4098,8 @@ def warn_transparent_union_attribute_zero_fields : Warning< def warn_attribute_type_not_supported : Warning< "%0 attribute argument not supported: %1">, InGroup; +def err_attribute_argument_not_supported : Error< + "%0 attribute argument %1 is not supported">; def warn_attribute_unknown_visibility : Warning<"unknown visibility %0">, InGroup; def warn_attribute_protected_visibility : diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c223e171cbb9e..d08fef8b28472 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -10563,7 +10563,7 @@ SYCLTypeAttr *Sema::MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI, SYCLTypeAttr::SYCLType TypeName) { if (const auto ExistingAttr = D->getAttr()) { if (ExistingAttr->getType() != TypeName) { - Diag(ExistingAttr->getLoc(), diag::warn_duplicate_attribute) + Diag(ExistingAttr->getLoc(), diag::err_duplicate_attribute) << ExistingAttr; Diag(CI.getLoc(), diag::note_previous_attribute); } @@ -10584,7 +10584,7 @@ static void handleSYCLTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SYCLTypeAttr::SYCLType Type; if (!SYCLTypeAttr::ConvertStrToSYCLType(II->getName(), Type)) { - S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; + S.Diag(AL.getLoc(), diag::err_attribute_argument_not_supported) << AL << II; return; } diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 89db97b2e5d51..58e1087a8ac60 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -103,6 +103,10 @@ static bool isAccessorPropertyType(QualType Ty, return false; } +static bool isSyclSpecialType(QualType Ty, Sema &S) { + return S.isTypeDecoratedWithDeclAttribute(Ty); +} + ExprResult Sema::ActOnSYCLBuiltinNumFieldsExpr(ParsedType PT) { TypeSourceInfo *TInfo = nullptr; QualType QT = GetTypeFromParser(PT, &TInfo); @@ -1152,11 +1156,10 @@ class KernelObjVisitor { for (const auto &Base : Range) { QualType BaseTy = Base.getType(); // Handle accessor class as base - if (SemaRef.isTypeDecoratedWithDeclAttribute( - BaseTy)) { + if (isSyclSpecialType(BaseTy, SemaRef)) (void)std::initializer_list{ (Handlers.handleSyclSpecialType(Owner, Base, BaseTy), 0)...}; - } else + else // For all other bases, visit the record visitRecord(Owner, Base, BaseTy->getAsCXXRecordDecl(), BaseTy, Handlers...); @@ -1235,7 +1238,7 @@ class KernelObjVisitor { template void visitField(const CXXRecordDecl *Owner, FieldDecl *Field, QualType FieldTy, HandlerTys &... Handlers) { - if (SemaRef.isTypeDecoratedWithDeclAttribute(FieldTy)) + if (isSyclSpecialType(FieldTy, SemaRef)) KF_FOR_EACH(handleSyclSpecialType, Field, FieldTy); else if (isSyclType(FieldTy, SYCLTypeAttr::spec_constant)) KF_FOR_EACH(handleSyclSpecConstantType, Field, FieldTy); @@ -1579,7 +1582,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler { } bool checkSyclSpecialType(QualType Ty, SourceRange Loc) { - assert(SemaRef.isTypeDecoratedWithDeclAttribute(Ty) && + assert(isSyclSpecialType(Ty, SemaRef) && "Should only be called on sycl special class types."); const RecordDecl *RecD = Ty->getAsRecordDecl(); if (IsSIMD && !isSyclAccessorType(Ty)) diff --git a/clang/test/CodeGenSYCL/Inputs/sycl.hpp b/clang/test/CodeGenSYCL/Inputs/sycl.hpp index 35c8ad4f83153..b6f06b1500304 100644 --- a/clang/test/CodeGenSYCL/Inputs/sycl.hpp +++ b/clang/test/CodeGenSYCL/Inputs/sycl.hpp @@ -1,6 +1,7 @@ #pragma once #define ATTR_SYCL_KERNEL __attribute__((sycl_kernel)) +#define __SYCL_TYPE(x) [[__sycl_detail__::sycl_type(x)]] extern "C" int printf(const char* fmt, ...); @@ -29,7 +30,7 @@ class __attribute__((sycl_special_class)) sampler { }; template -class __attribute__((sycl_type(group))) group { +class __SYCL_TYPE(group) group { public: group() = default; // fake constructor }; @@ -69,7 +70,7 @@ enum class address_space : int { } // namespace access // Dummy aspect enum with limited enumerators -enum class __attribute__((sycl_type(aspect))) aspect { +enum class __SYCL_TYPE(aspect) aspect { host = 0, cpu = 1, gpu = 2, @@ -119,7 +120,7 @@ namespace ext { namespace intel { namespace property { // Compile time known accessor property -struct __attribute__((sycl_type(buffer_location))) buffer_location { +struct __SYCL_TYPE(buffer_location) buffer_location { template class instance {}; }; } // namespace property @@ -130,7 +131,7 @@ namespace ext { namespace oneapi { namespace property { // Compile time known accessor property -struct __attribute__((sycl_type(no_alias))) no_alias { +struct __SYCL_TYPE(no_alias) no_alias { template class instance {}; }; } // namespace property @@ -172,7 +173,7 @@ template struct item { namespace ext { namespace oneapi { template -class __attribute__((sycl_type(accessor_property_list))) accessor_property_list {}; +class __SYCL_TYPE(accessor_property_list) accessor_property_list {}; } // namespace oneapi } // namespace ext @@ -201,7 +202,7 @@ template > -class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { +class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor { public: void use(void) const {} @@ -267,7 +268,7 @@ struct _ImageImplT { }; template -class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { +class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor { public: void use(void) const {} template @@ -292,7 +293,7 @@ class accessor -class __attribute__((sycl_special_class)) __attribute__((sycl_type(local_accessor))) +class __attribute__((sycl_special_class)) __SYCL_TYPE(local_accessor) local_accessor: public accessor { @@ -344,7 +345,7 @@ namespace ext { namespace oneapi { namespace experimental { template -class __attribute__((sycl_type(spec_constant))) spec_constant { +class __SYCL_TYPE(spec_constant) spec_constant { public: spec_constant() {} spec_constant(T Cst) {} @@ -375,11 +376,11 @@ int printf(const __SYCL_CONSTANT_AS char *__format, Args... args) { } // namespace oneapi } // namespace ext -class __attribute__((sycl_type(kernel_handler))) kernel_handler { +class __SYCL_TYPE(kernel_handler) kernel_handler { void __init_specialization_constants_buffer(char *specialization_constants_buffer) {} }; -template class __attribute__((sycl_type(specialization_id))) specialization_id { +template class __SYCL_TYPE(specialization_id) specialization_id { public: using value_type = T; diff --git a/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp b/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp index da9756916848b..7ca8bbb86a205 100644 --- a/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp +++ b/clang/test/CodeGenSYCL/accessor-readonly-invalid-lib.cpp @@ -60,7 +60,7 @@ struct _ImplT { template -class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { +class __attribute__((sycl_special_class)) [[__sycl_detail__::sycl_type(accessor)]] accessor { public: void use(void) const {} diff --git a/clang/test/SemaSYCL/Inputs/sycl.hpp b/clang/test/SemaSYCL/Inputs/sycl.hpp index 50079ba2be8d0..dd2c08d774c62 100644 --- a/clang/test/SemaSYCL/Inputs/sycl.hpp +++ b/clang/test/SemaSYCL/Inputs/sycl.hpp @@ -1,6 +1,8 @@ #ifndef SYCL_HPP #define SYCL_HPP +#define __SYCL_TYPE(x) [[__sycl_detail__::sycl_type(x)]] + // Shared code for SYCL tests namespace sycl { @@ -39,7 +41,7 @@ enum class address_space : int { } // namespace access // Dummy aspect enum with limited enumerators -enum class __attribute__((sycl_type(aspect))) aspect { +enum class __SYCL_TYPE(aspect) aspect { host = 0, cpu = 1, gpu = 2, @@ -54,7 +56,7 @@ class property_list {}; namespace ext { namespace intel { namespace property { -struct __attribute__((sycl_type(buffer_location))) buffer_location { +struct __SYCL_TYPE(buffer_location) buffer_location { template class instance {}; }; } // namespace property @@ -64,7 +66,7 @@ struct __attribute__((sycl_type(buffer_location))) buffer_location { namespace ext { namespace oneapi { template -class __attribute__((sycl_type(accessor_property_list))) accessor_property_list {}; +class __SYCL_TYPE(accessor_property_list) accessor_property_list {}; // device_global type decorated with attributes template @@ -131,7 +133,7 @@ template > -class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { +class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor { public: void use(void) const {} void use(void *) const {} @@ -194,7 +196,7 @@ struct _ImageImplT { }; template -class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) accessor { +class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor { public: void use(void) const {} template @@ -208,7 +210,7 @@ class __attribute__((sycl_special_class)) __attribute__((sycl_type(accessor))) }; template -class __attribute__((sycl_special_class)) __attribute__((sycl_type(local_accessor))) +class __attribute__((sycl_special_class)) __SYCL_TYPE(local_accessor) local_accessor: public accessor { @@ -260,12 +262,12 @@ struct get_kernel_name_t { }; template -class __attribute__((sycl_type(group))) group { +class __SYCL_TYPE(group) group { public: group() = default; // fake constructor }; -class __attribute__((sycl_type(kernel_handler))) kernel_handler { +class __SYCL_TYPE(kernel_handler) kernel_handler { void __init_specialization_constants_buffer(char *specialization_constants_buffer) {} }; @@ -393,7 +395,7 @@ namespace ext { namespace oneapi { namespace experimental { template -class __attribute__((sycl_type(spec_constant))) spec_constant { +class __SYCL_TYPE(spec_constant) spec_constant { public: spec_constant() {} explicit constexpr spec_constant(T defaultVal) : DefaultValue(defaultVal) {} diff --git a/clang/test/SemaSYCL/sycl-type-attr-ast.cpp b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp index d9dc48ac630be..cf295220fe7a9 100644 --- a/clang/test/SemaSYCL/sycl-type-attr-ast.cpp +++ b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp @@ -2,7 +2,7 @@ // Tests for AST of sycl_type() attribute -class __attribute__((sycl_type(accessor))) accessor {}; +class [[__sycl_detail__::sycl_type(accessor)]] accessor {}; // CHECK: CXXRecordDecl {{.*}} class accessor definition // CHECK: SYCLTypeAttr {{.*}} accessor @@ -10,23 +10,24 @@ class accessor; // CHECK: CXXRecordDecl {{.*}} prev {{.*}} class accessor // CHECK: SYCLTypeAttr {{.*}} Inherited accessor -enum class __attribute__((sycl_type(aspect))) aspect {}; +enum class [[__sycl_detail__::sycl_type(aspect)]] aspect {}; // CHECK: EnumDecl {{.*}} class aspect 'int' // CHECK: SYCLTypeAttr {{.*}} aspect template -class __attribute__((sycl_type(local_accessor))) local_accessor {}; +class [[__sycl_detail__::sycl_type(local_accessor)]] local_accessor {}; // CHECK: ClassTemplateDecl {{.*}} local_accessor // CHECK: CXXRecordDecl {{.*}} class local_accessor definition // CHECK: SYCLTypeAttr {{.*}} local_accessor -class __attribute__((sycl_type(spec_constant))) __attribute__((sycl_type(spec_constant))) spec_constant; +class [[__sycl_detail__::sycl_type(spec_constant)]] +[[__sycl_detail__::sycl_type(spec_constant)]] spec_constant; // CHECK: CXXRecordDecl {{.*}} spec_constant // CHECK: SYCLTypeAttr {{.*}} spec_constant // CHECK-NOT: SYCLTypeAttr {{.*}} spec_constant template <> -class __attribute__((sycl_type(local_accessor))) local_accessor {}; +class [[__sycl_detail__::sycl_type(local_accessor)]] local_accessor {}; // CHECK: ClassTemplateSpecializationDecl {{.*}} class local_accessor definition // CHECK: SYCLTypeAttr {{.*}} local_accessor diff --git a/clang/test/SemaSYCL/sycl-type-attr.cpp b/clang/test/SemaSYCL/sycl-type-attr.cpp index 0f9b57c3bdc63..85d3a17fcd353 100644 --- a/clang/test/SemaSYCL/sycl-type-attr.cpp +++ b/clang/test/SemaSYCL/sycl-type-attr.cpp @@ -5,41 +5,42 @@ #include "sycl.hpp" // expected-error@+1{{'sycl_type' attribute only applies to classes}} -__attribute__((sycl_type(accessor))) int a; +[[__sycl_detail__::sycl_type(accessor)]] int a; // expected-error@+1{{'sycl_type' attribute only applies to classes}} -__attribute__((sycl_type(accessor))) void func1() {} +[[__sycl_detail__::sycl_type(accessor)]] void func1() {} // expected-error@+1{{'sycl_type' attribute requires an identifier}} -class __attribute__((sycl_type("accessor"))) A {}; +class [[__sycl_detail__::sycl_type("accessor")]] A {}; // expected-error@+1{{'sycl_type' attribute takes one argument}} -class __attribute__((sycl_type())) B {}; +class [[__sycl_detail__::sycl_type()]] B {}; -// expected-warning@+1{{'sycl_type' attribute argument not supported: 'NotValidType'}} -class __attribute__((sycl_type(NotValidType))) C {}; +// expected-error@+1{{'sycl_type' attribute argument 'NotValidType' is not supported}} +class [[__sycl_detail__::sycl_type(NotValidType)]] C {}; // expected-note@+1{{previous attribute is here}} -class __attribute__((sycl_type(spec_constant))) spec_constant; -// expected-warning@+1{{attribute 'sycl_type' is already applied with different arguments}} -class __attribute__((sycl_type(accessor))) spec_constant {}; +class [[__sycl_detail__::sycl_type(spec_constant)]] spec_constant; +// expected-error@+1{{attribute 'sycl_type' is already applied with different arguments}} +class [[__sycl_detail__::sycl_type(accessor)]] spec_constant {}; -// expected-warning@+2{{attribute 'sycl_type' is already applied with different arguments}} +// expected-error@+2{{attribute 'sycl_type' is already applied with different arguments}} // expected-note@+1{{previous attribute is here}} -class __attribute__((sycl_type(group))) __attribute__((sycl_type(accessor))) group {}; +class [[__sycl_detail__::sycl_type(group)]] [[__sycl_detail__::sycl_type(accessor)]] group {}; // Valid usage - -class __attribute__((sycl_type(accessor))) accessor {}; +class [[__sycl_detail__::sycl_type(accessor)]] accessor {}; template -class __attribute__((sycl_type(local_accessor))) local_accessor {}; +class [[__sycl_detail__::sycl_type(local_accessor)]] local_accessor {}; -enum class __attribute__((sycl_type(aspect))) aspect {}; +enum class [[__sycl_detail__::sycl_type(aspect)]] aspect {}; // No diagnostic for matching arguments. -class __attribute__((sycl_type(kernel_handler))) kernel_handler; -class __attribute__((sycl_type(kernel_handler))) __attribute__((sycl_type(kernel_handler))) kernel_handler {}; +class [[__sycl_detail__::sycl_type(kernel_handler)]] kernel_handler; +class [[__sycl_detail__::sycl_type(kernel_handler)]] +[[__sycl_detail__::sycl_type(kernel_handler)]] kernel_handler {}; class kernel_handler; diff --git a/sycl/include/sycl/detail/defines.hpp b/sycl/include/sycl/detail/defines.hpp index d80dd2c2a8504..23df19ce4b284 100644 --- a/sycl/include/sycl/detail/defines.hpp +++ b/sycl/include/sycl/detail/defines.hpp @@ -27,8 +27,8 @@ #define __SYCL_SPECIAL_CLASS #endif -#if __has_attribute(sycl_type) -#define __SYCL_TYPE(x) __attribute__((sycl_type(x))) +#if __has_cpp_attribute(__sycl_detail__::sycl_type) +#define __SYCL_TYPE(x) [[__sycl_detail__::sycl_type(x)]] #else #define __SYCL_TYPE(x) #endif From ddbec099b073860b8f670cd4320a78be2b9756a8 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Thu, 1 Sep 2022 08:33:22 -0700 Subject: [PATCH 4/6] Remove unnecessary includes and options from tests Signed-off-by: Elizabeth Andrews --- clang/test/SemaSYCL/sycl-type-attr-ast.cpp | 2 +- clang/test/SemaSYCL/sycl-type-attr.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/test/SemaSYCL/sycl-type-attr-ast.cpp b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp index cf295220fe7a9..71de3a67667da 100644 --- a/clang/test/SemaSYCL/sycl-type-attr-ast.cpp +++ b/clang/test/SemaSYCL/sycl-type-attr-ast.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -ast-dump %s | FileCheck %s +// RUN: %clang_cc1 -fsycl-is-device -ast-dump %s | FileCheck %s // Tests for AST of sycl_type() attribute diff --git a/clang/test/SemaSYCL/sycl-type-attr.cpp b/clang/test/SemaSYCL/sycl-type-attr.cpp index 85d3a17fcd353..7405938554f1e 100644 --- a/clang/test/SemaSYCL/sycl-type-attr.cpp +++ b/clang/test/SemaSYCL/sycl-type-attr.cpp @@ -2,8 +2,6 @@ // Diagnostic tests for sycl_type() attribute -#include "sycl.hpp" - // expected-error@+1{{'sycl_type' attribute only applies to classes}} [[__sycl_detail__::sycl_type(accessor)]] int a; From 0418feaca6696f967e9b673ee89c7fbf8109eed2 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Thu, 1 Sep 2022 08:39:43 -0700 Subject: [PATCH 5/6] Delete unused option in test RUN Signed-off-by: Elizabeth Andrews --- clang/test/SemaSYCL/sycl-type-attr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaSYCL/sycl-type-attr.cpp b/clang/test/SemaSYCL/sycl-type-attr.cpp index 7405938554f1e..fc41ab48cb44f 100644 --- a/clang/test/SemaSYCL/sycl-type-attr.cpp +++ b/clang/test/SemaSYCL/sycl-type-attr.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -verify %s +// RUN: %clang_cc1 -fsycl-is-device -verify %s // Diagnostic tests for sycl_type() attribute From cca9a85034b8a47d3298fc2ac03d32685cb0e867 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Thu, 1 Sep 2022 09:40:53 -0700 Subject: [PATCH 6/6] Implement review comments Signed-off-by: Elizabeth Andrews --- clang/lib/Sema/SemaDeclAttr.cpp | 4 ++-- clang/lib/Sema/SemaSYCL.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d08fef8b28472..7097d4223182c 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -10431,7 +10431,7 @@ bool isDeviceAspectType(const QualType Ty) { if (!ET) return false; - if (const SYCLTypeAttr *Attr = ET->getDecl()->getAttr()) + if (const auto *Attr = ET->getDecl()->getAttr()) return Attr->getType() == SYCLTypeAttr::aspect; return false; @@ -10561,7 +10561,7 @@ static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SYCLTypeAttr *Sema::MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI, SYCLTypeAttr::SYCLType TypeName) { - if (const auto ExistingAttr = D->getAttr()) { + if (const auto *ExistingAttr = D->getAttr()) { if (ExistingAttr->getType() != TypeName) { Diag(ExistingAttr->getLoc(), diag::err_duplicate_attribute) << ExistingAttr; diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 58e1087a8ac60..a763109d39aad 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -72,13 +72,13 @@ static bool isSyclType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) { if (!RD) return false; - if (const SYCLTypeAttr *Attr = RD->getAttr()) + if (const auto *Attr = RD->getAttr()) return Attr->getType() == TypeName; if (const auto *CTSD = dyn_cast(RD)) if (CXXRecordDecl *TemplateDecl = CTSD->getSpecializedTemplate()->getTemplatedDecl()) - if (const SYCLTypeAttr *Attr = TemplateDecl->getAttr()) + if (const auto *Attr = TemplateDecl->getAttr()) return Attr->getType() == TypeName; return false; @@ -97,7 +97,7 @@ static bool isAccessorPropertyType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) { if (const auto *RD = Ty->getAsCXXRecordDecl()) if (const auto *Parent = dyn_cast(RD->getParent())) - if (const SYCLTypeAttr *Attr = Parent->getAttr()) + if (const auto *Attr = Parent->getAttr()) return Attr->getType() == TypeName; return false;