[cfe-dev] Retrieving address space from the AST using attributes

Simon Brand tartanllama at gmail.com
Mon Jan 14 04:13:50 PST 2013

Hi there,
Part of a program I am writing traverses the AST for an OpenCL program. I am
attempting to differentiate between accesses to variables in global and
local memory. These are defined like this:

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

__kernel void test(__global float *in, __local float *out)

The problem is that I can't seem to retrieve the address space from the AST.
My current approaches are all in the function:
bool VisitDeclRefExpr(const DeclRefExpr *Expr)

I have tried:
Expr->getDecl()->getType().getAddressSpace() //returns 0
Expr->getDecl()->getType()->getAs<AttributedType>() //returns null pointer
Context->getDeclAttrs(Expr) //returns empty AttrVec

However, calling Expr->getNameInfo().getName().getAsString() returns
"__attribute__((address_space(1))) float *" for the "in" variable and
"__attribute__((address_space(3))) float *" for the "out" variable, as one
would expect.

Is there something I'm doing wrong or a correct way to do this? I am using
Clang v3.2.

View this message in context: http://clang-developers.42468.n3.nabble.com/Retrieving-address-space-from-the-AST-using-attributes-tp4029688.html
Sent from the Clang Developers mailing list archive at Nabble.com.

More information about the cfe-dev mailing list