[cfe-dev] OpenCL and Type Poisoning

Speziale Ettore speziale.ettore at gmail.com
Wed Feb 2 01:31:55 PST 2011


> Instead, we can store the attribute on the typedef and use
> a generic convenience function for non-canonical types which
> walks the chain testing for the presence of a specific attribute.
> Maybe something like this (Type member function):
> template <typename T> T *getTypedefAttr() {
>   Type *T = this;
>   while (TypedefType *TT = T->getAs<TypedefType>()) {
>     TypedefDecl *TD = TT->getDecl();
>     if (T *A = TD->getAttr<T>())
>       return A;
>     T = TD->getUnderlyingType();
>   }
>   return 0;
> }
> Then in the trivial case, we can use
> T->getTypedefAttr<OpenCLKernelPoisonAttr>()
> to test for the attribute.

The Type::getTypedefAttr accessor cannot be implemented in Type.h,
because it needs the complete definition of TypedefDecl.h. Decl.h
includes Type.h, so I've implemented Type::getTypedefAttr out-of-line in
Decl.h. It this right? Or getTypedefAttr should be implemented as a
member function of Decl?

> Perhaps.  The OpenCL spec doesn't seem to say anything either way
> about this, but it seems reasonable to disallow it for the reasons
> given in the spec (and perhaps propose this restriction for a later
> version of the spec).  Likewise pointers to poisoned types, I think.

I agree.

> Thanks,

Thank you for your advices,
speziale.ettore at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kernel-poison-02-02-2011.diff
Type: text/x-patch
Size: 12780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110202/3c176082/attachment.bin>

More information about the cfe-dev mailing list