Anastasia created this revision.
Anastasia added a reviewer: mantognini.
Herald added subscribers: ebevhan, yaxunl.
Anastasia requested review of this revision.

OpenCL doesn't allow function pointers and therefore pointers to member 
functions are to be restricted too.

Even if this C++ feature provides more insight of the function that might be 
pointed too it inherited the same fundamental issue - can lead to the divergent 
execution of big fragments of code that are very inefficient.


https://reviews.llvm.org/D93958

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCLCXX/members.cl


Index: clang/test/SemaOpenCLCXX/members.cl
===================================================================
--- /dev/null
+++ clang/test/SemaOpenCLCXX/members.cl
@@ -0,0 +1,22 @@
+//RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -verify -fsyntax-only
+
+// Check that pointer to member functions are diagnosed
+struct C {
+  void f(int n);
+};
+
+typedef void (C::*p_t)(int);
+
+template <class T> struct remove_reference { typedef T type; };
+template <class T> struct remove_reference<T &> { typedef T type; };
+
+template <typename T>
+void templ_test() {
+  typename remove_reference<T>::type *ptr; //expected-error{{pointers to 
functions are not allowed}}
+}
+
+void test() {
+  void (C::*p)(int);       //expected-error{{pointers to functions are not 
allowed}}
+  p_t p1;                  //expected-error{{pointers to functions are not 
allowed}}
+  templ_test<int (&)()>(); //expected-note{{in instantiation of function 
template specialization}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6748,8 +6748,8 @@
 
   // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
   QualType NR = R;
-  while (NR->isPointerType()) {
-    if (NR->isFunctionPointerType()) {
+  while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
+    if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
       Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
       D.setInvalidType();
       return false;


Index: clang/test/SemaOpenCLCXX/members.cl
===================================================================
--- /dev/null
+++ clang/test/SemaOpenCLCXX/members.cl
@@ -0,0 +1,22 @@
+//RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -verify -fsyntax-only
+
+// Check that pointer to member functions are diagnosed
+struct C {
+  void f(int n);
+};
+
+typedef void (C::*p_t)(int);
+
+template <class T> struct remove_reference { typedef T type; };
+template <class T> struct remove_reference<T &> { typedef T type; };
+
+template <typename T>
+void templ_test() {
+  typename remove_reference<T>::type *ptr; //expected-error{{pointers to functions are not allowed}}
+}
+
+void test() {
+  void (C::*p)(int);       //expected-error{{pointers to functions are not allowed}}
+  p_t p1;                  //expected-error{{pointers to functions are not allowed}}
+  templ_test<int (&)()>(); //expected-note{{in instantiation of function template specialization}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6748,8 +6748,8 @@
 
   // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
   QualType NR = R;
-  while (NR->isPointerType()) {
-    if (NR->isFunctionPointerType()) {
+  while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
+    if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
       Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
       D.setInvalidType();
       return false;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D93958: [OpenCL]... Anastasia Stulova via Phabricator via cfe-commits

Reply via email to