From 39989dadd3cf3a82602c78a7e9d8ce535ab97017 Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Tue, 29 Jan 2013 10:54:06 +0000 Subject: [PATCH] Add a diagnostic for an OpenCL kernel with a pointer pointer argument. Also refactor the surrounding code a little. llvm-svn: 173791 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaDecl.cpp | 23 ++++++++++++++++------- clang/test/SemaOpenCL/invalid-kernel.cl | 3 +++ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 clang/test/SemaOpenCL/invalid-kernel.cl diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 86c0691..6e27d13 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6105,6 +6105,8 @@ def err_invalid_astype_of_different_size : Error< "invalid reinterpretation: sizes of %0 and %1 must match">; def err_static_kernel : Error< "kernel functions cannot be declared static">; +def err_opencl_ptrptr_kernel_arg : Error< + "kernel argument cannot be declared as a pointer to a pointer">; def err_static_function_scope : Error< "variables in function scope cannot be declared static">; def err_opencl_bitfields : Error< diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9c36664..56db548 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6211,7 +6211,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } if (NewFD->hasAttr()) { - // OpenCL v1.2 s6.8 static is invalid for kernel functions. if ((getLangOpts().OpenCLVersion >= 120) && (SC == SC_Static)) { @@ -6219,17 +6218,27 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, D.setInvalidType(); } - // OpenCL v1.2 s6.8 n: - // Arguments to kernel functions in a program cannot be declared to be of - // type event_t. for (FunctionDecl::param_iterator PI = NewFD->param_begin(), PE = NewFD->param_end(); PI != PE; ++PI) { - if ((*PI)->getType()->isEventT()) { - Diag((*PI)->getLocation(), diag::err_event_t_kernel_arg); + ParmVarDecl *Param = *PI; + QualType PT = Param->getType(); + + // OpenCL v1.2 s6.9.a: + // A kernel function argument cannot be declared as a + // pointer to a pointer type. + if (PT->isPointerType() && PT->getPointeeType()->isPointerType()) { + Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_arg); + D.setInvalidType(); + } + + // OpenCL v1.2 s6.8 n: + // A kernel function argument cannot be declared + // of event_t type. + if (PT->isEventT()) { + Diag(Param->getLocation(), diag::err_event_t_kernel_arg); D.setInvalidType(); } } - } MarkUnusedFileScopedDecl(NewFD); diff --git a/clang/test/SemaOpenCL/invalid-kernel.cl b/clang/test/SemaOpenCL/invalid-kernel.cl new file mode 100644 index 0000000..a06b0e1 --- /dev/null +++ b/clang/test/SemaOpenCL/invalid-kernel.cl @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -verify %s + +kernel void no_ptrptr(global int **i) { } // expected-error{{kernel argument cannot be declared as a pointer to a pointer}} -- 2.7.4