r173791 - Add a diagnostic for an OpenCL kernel with a pointer pointer argument.

Joey Gouly joey.gouly at arm.com
Tue Jan 29 02:54:06 PST 2013


Author: joey
Date: Tue Jan 29 04:54:06 2013
New Revision: 173791

URL: http://llvm.org/viewvc/llvm-project?rev=173791&view=rev
Log:

Add a diagnostic for an OpenCL kernel with a pointer pointer argument.
Also refactor the surrounding code a little.

Added:
    cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173791&r1=173790&r2=173791&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 29 04:54:06 2013
@@ -6105,6 +6105,8 @@ def err_invalid_astype_of_different_size
   "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<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173791&r1=173790&r2=173791&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 29 04:54:06 2013
@@ -6211,7 +6211,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, 
   }
 
   if (NewFD->hasAttr<OpenCLKernelAttr>()) {
-
     // 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, 
       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);

Added: cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel.cl?rev=173791&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel.cl (added)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel.cl Tue Jan 29 04:54:06 2013
@@ -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}}





More information about the cfe-commits mailing list