[cfe-dev] Implementing address space via custom C++11 attribute

Patrik EKlöf via cfe-dev cfe-dev at lists.llvm.org
Fri Feb 3 12:58:44 PST 2017


Hello dear community,

 

I’ve been trying to implement a way to set address spaces using a custom
C++11-style attribute, but I’ve been running into problems. The syntax I’m
trying to use is:

 

[[vms::ptr_32]] int* HiIAmA32BitPtr{ (int*)0xFFFF'FFFF };

 

But apparently clang ignores those C++11-style attributes. Looking at the
source, it’s because the attribute isn’t attached properly to the DeclSpec
since


 

DeclaratorChunk& DeclType = D.getTypeObject(chunkIndex);

 


returns NULL. Not sure why, or what it is doing. The alternative way of
doing it that I found is doing:

 

int* [[vms::ptr_32]] HiIAmA32BitPtr{ (int*)0xFFFF'FFFF };

 

This attribute is detected properly, but the type passed into
processTypeAttrs is int* (apparently if using the
__attribute((address_space)) syntax, it passes in regulator int), and
attaching the address space to int* doesn’t seem to work as clang creates an
llvm::type (lib/CodeGen/CodeGenTypes.cpp) using the address space of the
pointee instead of the actual pointer type. That seems weird to me, but I
don’t know what exactly address spaces are or how they work.

 

So I’m a little confused on how to approach this. I would like the first
syntax to work if possible, but I’m not sure how one would go about
implementing that without breaking anything. The second syntax seems to
behave in a non-ideal way, by passing in int* instead of int. Not sure how
one would go about fixing that, or if one should just make a hack to try to
get the underlying type. I use address spaces since it seems like a good way
to use mixed pointer sizes in the same translation unit.

 

Any ideas or thoughts?

 

Regards,

Patrik Eklöf

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170203/4ba2d3e7/attachment.html>


More information about the cfe-dev mailing list