[PATCH] D33821: [OpenCL] Harden function pointer diagnostics.

Alexey Bader via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 2 11:09:42 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL304575: [OpenCL] Harden function pointer diagnostics. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D33821?vs=101181&id=101242#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33821

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaOpenCL/func.cl


Index: cfe/trunk/lib/Sema/SemaType.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -1881,6 +1881,11 @@
     return QualType();
   }
 
+  if (T->isFunctionType() && getLangOpts().OpenCL) {
+    Diag(Loc, diag::err_opencl_function_pointer);
+    return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
     return QualType();
 
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -6160,7 +6160,7 @@
     QualType NR = R;
     while (NR->isPointerType()) {
       if (NR->isFunctionPointerType()) {
-        Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer_variable);
+        Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
         D.setInvalidType();
         break;
       }
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7268,7 +7268,7 @@
   "invalid conversion between vector type %0 and integer type %1 "
   "of different size">;
 
-def err_opencl_function_pointer_variable : Error<
+def err_opencl_function_pointer : Error<
   "pointers to functions are not allowed">;
 
 def err_opencl_taking_function_address : Error<
Index: cfe/trunk/test/SemaOpenCL/func.cl
===================================================================
--- cfe/trunk/test/SemaOpenCL/func.cl
+++ cfe/trunk/test/SemaOpenCL/func.cl
@@ -4,8 +4,15 @@
 void vararg_f(int, ...);                    // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
 void __vararg_f(int, ...);
 typedef void (*vararg_fptr_t)(int, ...);    // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
+                                            // expected-error at -1{{pointers to functions are not allowed}}
 int printf(__constant const char *st, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
 
+// Struct type with function pointer field
+typedef struct s
+{
+   void (*f)(struct s *self, int *i);       // expected-error{{pointers to functions are not allowed}}
+} s_t;
+
 //Function pointer
 void foo(void*);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33821.101242.patch
Type: text/x-patch
Size: 2460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170602/01dd80a6/attachment.bin>


More information about the cfe-commits mailing list