r304575 - [OpenCL] Harden function pointer diagnostics.
Alexey Bader via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 2 11:08:58 PDT 2017
Author: bader
Date: Fri Jun 2 13:08:58 2017
New Revision: 304575
URL: http://llvm.org/viewvc/llvm-project?rev=304575&view=rev
Log:
[OpenCL] Harden function pointer diagnostics.
Summary: Improve OpenCL type checking by rejecting function pointer types.
Reviewers: Anastasia, yaxunl
Reviewed By: Anastasia
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D33821
Modified:
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
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=304575&r1=304574&r2=304575&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 2 13:08:58 2017
@@ -7268,7 +7268,7 @@ def err_invalid_conversion_between_vecto
"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<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=304575&r1=304574&r2=304575&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jun 2 13:08:58 2017
@@ -6160,7 +6160,7 @@ NamedDecl *Sema::ActOnVariableDeclarator
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;
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=304575&r1=304574&r2=304575&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Jun 2 13:08:58 2017
@@ -1881,6 +1881,11 @@ QualType Sema::BuildPointerType(QualType
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();
Modified: cfe/trunk/test/SemaOpenCL/func.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/func.cl?rev=304575&r1=304574&r2=304575&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/func.cl (original)
+++ cfe/trunk/test/SemaOpenCL/func.cl Fri Jun 2 13:08:58 2017
@@ -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*);
More information about the cfe-commits
mailing list