Clang and OpenCL address spaces


I'm currently experimenting with the idea of a generic OpenCL
implementation targeting a symbolic virtual machine [1], using Clang
as the kernel front end.

I am trying to determine how to define address space qualifier macros
such as __local so that they map into Clang's view of the world.
There seems to be no (open source) OpenCL implementation which has
reached this issue yet (I looked at Clover, which is the only open
source implementation I am aware of). So far I have figured out
that I need to have each macro declare an address_space attribute,
i.e. something like this:

#define __local __attribute__((address_space(1)))

The main issue here is that this won't work for automatic variables.
I get errors such as "error: automatic variable qualified with an
address space".

From my understanding of the OpenCL specification, setting the address

space on an automatic variable is supposed to not only change the
address space but also make the variable static (as the term is defined
in standard C). Adding 'static' to the qualifier macro definitions
won't work too well because the qualifiers can also appear in other

Ideally I'd like this implementation to work with an unmodified
version of Clang. Currently the best way forward as I see it would be
a patch to force automatic variables with a declared address space to
become static if OpenCL is enabled. Would this be welcome? The only
downside I can think of is that a vendor may choose (or have chosen)
to implement the address space qualifiers in a different way, but since
most of the infrastructure seems to point towards the address_space
attribute this doesn't seem likely to me.

I've attached a minimal test case which I would ideally like to be
compilable (right now I'm getting the error message quoted above at
the line that declares 'x', the automatic variable). For now I'm
using the standard driver to try to compile this.

Thanks, (86 Bytes)

If that's how OpenCL is specified to work, then changing the front-end to
automatically add 'static' to local variables of address-space-qualified type
is a very reasonable solution. We would accept a patch for this.