[cfe-dev] OpenCL and Type Poisoning

Speziale Ettore speziale.ettore at gmail.com
Wed Jan 26 00:02:45 PST 2011

Hi everyone.

I'm currently investigating how to implement "type poisoning", required
to disallow using some types in OpenCL kernel parameters. As example, an
OpenCL kernel cannot have a size_t parameter.

Since I cannot check the QualType to detect if parameter type is not
good, Peter Collingbourne suggests me to look for something like the
"#pragma GCC poison" attribute.

I've tried to use that pragma, to poison a type, however, the pragma
poison all identifiers, so

#pragma GCC poison size_t

typedef long size_t; // Here a diagnostic is issued

kernel void foor(size_t err) // I want the diagostic to be issuded here.

I have tried to implement an "openlcl_kernel_poison" pragma, but I've
seen that the pragma construct is too far from what I want to do. Thus,
I've tried to implement the same think with an attribute:

typedef long size_t __attribute__((opencl_kernel_poison));

kernel void foo(size_t err); // The diagnostic is issued here

While handling "opencl_kernel_function" attribute (code from Anton's
patch), I recursively walk the typedef chain looking for declaration
marked with the "opencl_kernel_poision" attribute. This seems working,
however I don't think this to be the right solution.

>From my point of view, the "opencl_kernel_poison" attribute can be
generalized to a "type_poison" attribute. It can be applied to any type
declararation, marking the defined type poisoned. It should be handled
like a type attribute, (e.g. "address_space"), and stored inside the
clang::Qualifiers class as an extended qualifiers (There should be a
free bit in clang::Qualifiers::Mask).

Using this approach, detecting whether a type is poisoned is

I don't known if that attribute can be usefull also for aggregated

typedef long size_t __attribute__((type_poison))__;

struct err_1 {
  size_t err_2;

The struct err_1 should also be poisoned.

I attach the "opencl_kernel_poison" patch, only as reference. What do
you think about the "type_poison" approach. Is it usefull? Can it be
used also in languages other than OpenCL?

Have a nice day,
speziale.ettore at gmail.com

More information about the cfe-dev mailing list