From 2d2477ee1f61b480d1a479d03f7ae28d586d1d18 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Tue, 1 Feb 2022 08:24:17 -0800 Subject: [PATCH 1/4] Fix llorg/sycl-web pulldown issue Signed-off-by: Zahira Ammarguellat --- .../clang/AST/CXXRecordDeclDefinitionBits.def | 3 +++ clang/include/clang/AST/DeclCXX.h | 3 +++ .../clang/Basic/DiagnosticSemaKinds.td | 4 ++++ clang/lib/AST/DeclCXX.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 22 ++++++++++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def index 9b270682f8cf0..cdf0804680ad0 100644 --- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def +++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def @@ -112,6 +112,9 @@ FIELD(HasVariantMembers, 1, NO_MERGE) /// True if there no non-field members declared by the user. FIELD(HasOnlyCMembers, 1, NO_MERGE) +/// True if there is an '__init' method defined by the user. +FIELD(HasInitMethod, 1, NO_MERGE) + /// True if any field has an in-class initializer, including those /// within anonymous unions or structs. FIELD(HasInClassInitializer, 1, NO_MERGE) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index b54e6b0ac2171..2833df0505dac 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -1139,6 +1139,9 @@ class CXXRecordDecl : public RecordDecl { /// \note This does NOT include a check for union-ness. bool isEmpty() const { return data().Empty; } + void setInitMethod(bool Val) { data().HasInitMethod = Val; } + bool hasInitMethod() const { return data().HasInitMethod; } + bool hasPrivateFields() const { return data().HasPrivateFields; } diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 17319c34f27b6..51be4d834c6b0 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11493,6 +11493,10 @@ def warn_sycl_kernel_return_type : Warning< "function template with 'sycl_kernel' attribute must have a 'void' return type">, InGroup; +def err_sycl_special_type_num_init_method : Error< + "types with 'sycl_special_class' attribute must have one and only one '__init' " + "method defined">; + def err_bit_int_bad_size : Error<"%select{signed|unsigned}0 _BitInt must " "have a bit size of at least %select{2|1}0">; def err_bit_int_max_size : Error<"%select{signed|unsigned}0 _BitInt of bit " diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 108113274b8e0..a15498c89d6a1 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -111,7 +111,7 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) HasDeclaredCopyAssignmentWithConstParam(false), IsAnyDestructorNoReturn(false), IsLambda(false), IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), - HasODRHash(false), Definition(D) {} + HasODRHash(false), Definition(D), HasInitMethod(false) {} CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { return Bases.get(Definition->getASTContext().getExternalSource()); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b997024bcda20..8e13f2bfcafb6 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9194,6 +9194,13 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union); NewFD->setInvalidDecl(); } + if ((Parent->isClass() || Parent->isStruct()) && + Parent->hasAttr() && + NewFD->getKind() == Decl::Kind::CXXMethod && + NewFD->getName() == "__init" && D.isFunctionDefinition()) { + if (auto *Def = Parent->getDefinition()) + Def->setInitMethod(true); + } } SetNestedNameSpecifier(*this, NewFD, D); @@ -16764,8 +16771,21 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD, RD->completeDefinition(); } - if (isa(Tag)) { + if (auto *RD = dyn_cast(Tag)) { FieldCollector->FinishClass(); + if (RD->hasAttr() && getLangOpts().SYCLIsDevice) { + auto *Def = RD->getDefinition(); + assert(Def && "The record is expected to have a completed definition"); + unsigned NumInitMethods = 0; + for (auto *Method : Def->methods()) { + if (!Method->getIdentifier()) + continue; + if (Method->getName() == "__init") + NumInitMethods++; + } + if (NumInitMethods > 1 || !Def->hasInitMethod()) + Diag(RD->getLocation(), diag::err_sycl_special_type_num_init_method); + } } // Exit this scope of this tag's definition. From 161777a153dedbed51c7e823458eefeba60daea9 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Tue, 1 Feb 2022 08:41:58 -0800 Subject: [PATCH 2/4] Fix llorg/sycl-web pulldown issue - format Signed-off-by: Zahira Ammarguellat --- clang/lib/Sema/SemaDecl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8e13f2bfcafb6..ee87506313e42 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9194,7 +9194,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_in_union); NewFD->setInvalidDecl(); } - if ((Parent->isClass() || Parent->isStruct()) && + if ((Parent->isClass() || Parent->isStruct()) && Parent->hasAttr() && NewFD->getKind() == Decl::Kind::CXXMethod && NewFD->getName() == "__init" && D.isFunctionDefinition()) { @@ -16779,7 +16779,7 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD, unsigned NumInitMethods = 0; for (auto *Method : Def->methods()) { if (!Method->getIdentifier()) - continue; + continue; if (Method->getName() == "__init") NumInitMethods++; } From a7ca20f325e78fa65baa5012f5e33dd3093108fb Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Tue, 1 Feb 2022 11:11:30 -0800 Subject: [PATCH 3/4] Fix llorg/sycl-web pulldown issue Signed-off-by: Zahira Ammarguellat --- clang/lib/AST/DeclCXX.cpp | 3 +-- clang/lib/Sema/SemaDecl.cpp | 2 +- sycl/include/CL/sycl/accessor.hpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index a15498c89d6a1..187680a4ef1f9 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -81,8 +81,7 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), HasOnlyCMembers(true), HasInClassInitializer(false), HasUninitializedReferenceMember(false), HasUninitializedFields(false), - HasInheritedConstructor(false), - HasInheritedDefaultConstructor(false), + HasInheritedConstructor(false), HasInheritedDefaultConstructor(false), HasInheritedAssignment(false), NeedOverloadResolutionForCopyConstructor(false), NeedOverloadResolutionForMoveConstructor(false), diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ee87506313e42..f3cca82e60e02 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9196,7 +9196,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } if ((Parent->isClass() || Parent->isStruct()) && Parent->hasAttr() && - NewFD->getKind() == Decl::Kind::CXXMethod && + NewFD->getKind() == Decl::Kind::CXXMethod && NewFD->getIdentifier() && NewFD->getName() == "__init" && D.isFunctionDefinition()) { if (auto *Def = Parent->getDefinition()) Def->setInitMethod(true); diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index ba2f5e15f373a..f7f9af164c7d6 100644 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -2200,7 +2200,7 @@ class __SYCL_SPECIAL_CLASS accessor -class __SYCL_SPECIAL_CLASS accessor : public detail::image_accessor { From 4d42a5c2c5eb3d77f720cb298691e165e768079e Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Tue, 1 Feb 2022 11:19:07 -0800 Subject: [PATCH 4/4] Fix llorg/sycl-web pulldown issue Signed-off-by: Zahira Ammarguellat --- sycl/include/CL/sycl/accessor.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index f7f9af164c7d6..cf13264b4fca0 100644 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -2200,8 +2200,8 @@ class __SYCL_SPECIAL_CLASS accessor -class accessor +class accessor : public detail::image_accessor { public: