Clang AST: find out functions with attribute(opencl_kernel_function)

Hi.
I'm currently developing a standalone tool using Clang to find (and do some
transformation) functions declared using the OpenCL kernel syntax, i.e.

kernel void fun(...) { }

While traversing the AST and dumping functions, I discovered "kernel" means
__attribute__(opencl_kernel_syntax).
Anyway, I'm not sure about how to determine is a functions has this
attribute.
By now, the code looks like:

FunctionDecl* function = static_cast<FunctionDecl*>(declaration);
if(function->hasAttrs()) {
  AttrVec attributes = function->getAttrs();
  for(Decl::attr_iterator iterator = function->attr_begin(); iterator !=
function->attr_end(); iterator++) {
       Attr* attribute = *iterator;
  }
}

Anyway, I'm not able to figure out how to use the class Attr to determine
that the attribute considered is just opencl_kernel_syntax.
Can you help me?

Thank you very much!

Would:

if (!FD->hasAttr())
return;

work? (see http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?revision=166019&view=markup)

Cheers,
/Manuel

Perfectly :slight_smile: Thank you thousand!