<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 3 February 2017 at 12:58, Patrik EKlöf via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-GB"><div class="gmail-m_-8675670916187612406WordSection1"><p class="MsoNormal">Hello dear community,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">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:<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">[[vms::ptr_32]] int* HiIAmA32BitPtr{ (int*)0xFFFF'FFFF };<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">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…<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">DeclaratorChunk</span><span style="font-size:9.5pt;font-family:consolas;color:black">& DeclType = D.getTypeObject(chunkIndex);<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="MsoNormal">…returns NULL. Not sure why, or what it is doing. The alternative way of doing it that I found is doing:<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">int* [[vms::ptr_32]] HiIAmA32BitPtr{ (int*)0xFFFF'FFFF };<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">This attribute is detected properly, but the type passed into <span style="font-size:9.5pt;font-family:consolas;color:black">processTypeAttrs </span>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.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">So I’m a little confused on how to approach this. I would like the first syntax to work if possible,</p></div></div></blockquote><div><br></div><div>That would be a mistake. An attribute in that position applies to the variable HiIAmA32BitPtr itself, not to its type. You should also consider cases like:</div><div><br></div><div>  int **p;</div><div><br></div><div>What if you want p to be a 32-bit pointer to a 64-bit pointer to int, or vice versa?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-GB"><div class="gmail-m_-8675670916187612406WordSection1"><p class="MsoNormal">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.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Any ideas or thoughts?</p></div></div></blockquote><div><br></div><div>It seems like what your attribute is really saying is that the 'int' lives in a 32-bit address space. So this could be written as:</div><div><br></div><div>int [[vms::ptr_32]] * HiIAmA32BitPtr{ (int*)0xFFFF'FFFF };</div><div><br></div><div>That is, HiIAmA32BitPtr is a pointer to an "int in some 32-bit address space".</div></div></div></div>