OpenCL attribute support in libclang

It appears that while (some) CUDA attributes are currently exposed in the libclang interface, there's no similar treatment for OpenCL attributes. In fact, parameter declaration attributes don't seem to appear at all when walking the AST (even as unexposed attributes).

When working with code analysis and generation for OpenCL kernels, this is obviously an important feature.

Does anyone know if a patch exists for this? If not, I will look into adding support patterned on the CUDA attribute support.



Here are initial patches that expose the inheritable attributes for OpenCL in libclang, including the python bindings.

As far as I can tell, since the address space attributes are type attributes, exposing them will require adding to the libclang API (which does not appear to have any generalized way to query type attributes at the moment). Any suggestions for this?

0001-Expose-OpenCL-attributes-in-AST.patch (2.73 KB)

0002-Add-additional-OpenCL-attributes-to-Python-binding.patch (772 Bytes)

LGTM, but this demonstrates the need for this to be automated more. At
some point, I think this should be automatically generated from instead of requiring manual intervention.


I agree regarding auto-generation; there's a lot of boilerplate here that could be auto-generated. Some things will probably need to be manually specified for the sake of API stability (such as enums for attributes and such, which need to be stable while the AST can change), but hopefully in only one place.

I think, however, that some bits of the interface will need re-thinking (especially as regards type attributes, which are currently exposed in a one-off way).

I would like to be able to use libclang for some basic semantic analysis for development tools, but right now there are several features lacking on that front.

-Paul Fox