[PATCH] Error on illegal OpenCL kernel argument types

Eli Friedman eli.friedman at gmail.com
Mon Jul 8 14:32:17 PDT 2013


+    if (const TypedefType *Typedef = dyn_cast<TypedefType>(PT)) {
+      const IdentifierInfo *Identifier = Typedef->getDecl()->getIdentifier();
+      StringRef Name = Identifier->getName();
+
+      if (Name == "size_t" ||
+          Name == "ptrdiff_t" ||
+          Name == "intptr_t" ||
+          Name == "uintptr_t") {
+        return false;
+      }
+    }

No.  It's completely insane to print an error message based on typedef
sugar.  Someone could write "typedef size_t mysize_t;", or "typedef
__typeof(sizeof(int)) mysize_t;", or "#if SIZE_MAX == UINT_MAX [...]
typdef unsigned mysize_t [...]".

+static const RecordType *getAsStructOrUnionType(QualType QT) {
+  const RecordType *RT = QT->getAsStructureType();
+  if (!RT)
+    RT = QT->getAsUnionType();
+
+  return RT;
+}

This is equivalent to QT->getAs<RecordType>().


+      if (!isValidOpenCLKernelArgumentType(QT)) {
+        // TODO: A more specific warning about which struct members forbid this
+        // would be useful
+        Diag(Param->getLocation(), diag::err_bad_kernel_arg_type) << PT;
+        D.setInvalidType();

Diag(FD->getLocation(), diag::note_field_declared_here);

Please just fix this.

+kernel void bool_arg(bool x) // expected-error{{'bool' cannot be used
to declare a kernel function argument}}
+{
+
+}

"kernel void bool_arg(bool x) {}" would save 3 lines of useless whitespace.

-Eli

On Wed, Jun 26, 2013 at 6:47 PM, Matt Arsenault
<Matthew.Arsenault at amd.com> wrote:
> Hi rsmith,
>
> OpenCL disallows various types (bool, size_t, pointers, or structs containing them) to be used for kernel arguments, but currently they are accepted. The error message in the struct case is currently a bit awkward since it doesn't describe which struct member is at fault for not allowing the kernel argument.
>
> http://llvm-reviews.chandlerc.com/D1052
>
> Files:
>   include/clang/Basic/DiagnosticSemaKinds.td
>   include/clang/Sema/Sema.h
>   lib/Sema/SemaDecl.cpp
>   test/SemaOpenCL/invalid-kernel-arguments.cl
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list