[PATCH] D33821: [OpenCL] Harden function pointer diagnostics.
Alexey Bader via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 2 03:31:31 PDT 2017
bader created this revision.
Improve OpenCL type checking by rejecting function pointer types.
https://reviews.llvm.org/D33821
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
lib/Sema/SemaType.cpp
test/SemaOpenCL/func.cl
Index: test/SemaOpenCL/func.cl
===================================================================
--- test/SemaOpenCL/func.cl
+++ 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*);
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ 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: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ 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: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ 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<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33821.101181.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170602/fdb3815b/attachment-0001.bin>
More information about the cfe-commits
mailing list