zahiraam created this revision.
zahiraam added reviewers: erichkeane, Fznamznon.
zahiraam requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118837

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaSYCL/special-class-attribute.cpp


Index: clang/test/SemaSYCL/special-class-attribute.cpp
===================================================================
--- clang/test/SemaSYCL/special-class-attribute.cpp
+++ clang/test/SemaSYCL/special-class-attribute.cpp
@@ -30,6 +30,14 @@
   void __init(){}
 };
 
+struct __attribute__((sycl_special_class)) struct6 {
+  struct6();
+  bool operator==(const struct6 &);
+  struct6 &operator()();
+  ~struct6();
+  void __init(){}
+};
+
 // Must have one and only one __init method defined
 class __attribute__((sycl_special_class)) class6 { // expected-error {{types 
with 'sycl_special_class' attribute must have one and only one '__init' method 
defined}}
   class6() {}
@@ -47,6 +55,14 @@
 struct __attribute__((sycl_special_class)) struct3;
 struct struct3 {}; // expected-error {{types with 'sycl_special_class' 
attribute must have one and only one '__init' method defined}}
 
+// expected-error@+1{{'sycl_special_class' attribute must have one and only 
one '__init' method defined}}
+struct __attribute__((sycl_special_class)) struct7 {
+  struct7();
+  bool operator==(const struct7 &);
+  struct7 &operator()();
+  ~struct7();
+};
+
 // Only classes
 [[clang::sycl_special_class]] int var1 = 0;       // expected-warning 
{{'sycl_special_class' attribute only applies to classes}}
 __attribute__((sycl_special_class)) int var2 = 0; // expected-warning 
{{'sycl_special_class' attribute only applies to classes}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9193,7 +9193,7 @@
       }
       if ((Parent->isClass() || Parent->isStruct()) &&
           Parent->hasAttr<SYCLSpecialClassAttr>() &&
-          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);


Index: clang/test/SemaSYCL/special-class-attribute.cpp
===================================================================
--- clang/test/SemaSYCL/special-class-attribute.cpp
+++ clang/test/SemaSYCL/special-class-attribute.cpp
@@ -30,6 +30,14 @@
   void __init(){}
 };
 
+struct __attribute__((sycl_special_class)) struct6 {
+  struct6();
+  bool operator==(const struct6 &);
+  struct6 &operator()();
+  ~struct6();
+  void __init(){}
+};
+
 // Must have one and only one __init method defined
 class __attribute__((sycl_special_class)) class6 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
   class6() {}
@@ -47,6 +55,14 @@
 struct __attribute__((sycl_special_class)) struct3;
 struct struct3 {}; // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
 
+// expected-error@+1{{'sycl_special_class' attribute must have one and only one '__init' method defined}}
+struct __attribute__((sycl_special_class)) struct7 {
+  struct7();
+  bool operator==(const struct7 &);
+  struct7 &operator()();
+  ~struct7();
+};
+
 // Only classes
 [[clang::sycl_special_class]] int var1 = 0;       // expected-warning {{'sycl_special_class' attribute only applies to classes}}
 __attribute__((sycl_special_class)) int var2 = 0; // expected-warning {{'sycl_special_class' attribute only applies to classes}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9193,7 +9193,7 @@
       }
       if ((Parent->isClass() || Parent->isStruct()) &&
           Parent->hasAttr<SYCLSpecialClassAttr>() &&
-          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);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to