<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 6, 2009, at 4:20 PM, Tanya Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 6, 2009, at 3:50 PM, John McCall wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div bgcolor="#ffffff" text="#000000">
Tanya Lattner wrote:
<blockquote cite="mid:8BC63CA3-0E0D-4F51-ACDC-E1C1205C063E@apple.com" type="cite"><br>
  <div>
  <div>On Oct 5, 2009, at 2:58 PM, Douglas Gregor wrote:</div>
  <br class="Apple-interchange-newline">
  <blockquote type="cite">
    <div style=""><br>
    <div>
    <div>On Oct 5, 2009, at 2:37 PM, Tanya Lattner wrote:</div>
    <br class="Apple-interchange-newline">
    <blockquote type="cite">
      <div style="">Hello,
      <div><br>
      </div>
      <div>I want to do a check on function parameters similar to the "<span class="Apple-style-span" style="color: rgb(51, 89, 93); font-family: Menlo; font-size: 11px;">err_arg_with_address_space"
      </span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">check that I added in</span></font><span class="Apple-style-span" style="color: rgb(51, 89, 93); font-family: Menlo; font-size: 11px;"> <span class="Apple-style-span" style="">ActOnParamDeclarator<span class="Apple-style-span" style="font-family: Helvetica; font-size: medium;"> (r83165)<span class="Apple-style-span" style="font-family: Menlo; font-size: 11px;">.
      <font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;">However, this time,
I only want to perform the check if the function has a specific
attribute. Is ActOnParamDeclarator the right place? I'm not seeing a
way to get the function attribute there. Or, any suggestion on where to
add this?</span></font></span></span></span></span></div>
      </div>
    </blockquote>
    </div>
    <div><br>
    </div>
ActOnParamDeclarator won't work, since that gets can get called by the
parser before we've seen the function attributes. I suggest putting
this check into ActOnFunctionDeclarator (e.g., where we check for
parameters of "void" type).
    <div><br>
    </div>
    </div>
  </blockquote>
  <div><br>
  </div>
  <div>Awesome, thanks! At this point in ActOnFunctionDeclarator, do
parameters know about their attributes? Specifically addr space
qualifiers. I'm thinking no because it always seems to think the
param's in addr space 0, but when I dump the QualType I can clearly see
the addr space attribute and its non zero, but I assume it just hasn't
been processed yet.</div>
  </div>
</blockquote>
<br>
ActOnFunctionDeclarator doesn't get called until all the parameters
have finished parsing, so all the attributes, address spaces, etc.
should be present.<br>
<br>
Can you post a code example where it thinks the parameter is in address
space 0 (I assume getAddressSpace() is returning 0)?<br>
<br></div></blockquote><div><br></div><div>Yes, I'm using getAddressSpace().</div><div><br></div><div>Here is a simple example:</div><div>__attribute__((annotate("random"))) void foo(__attribute__((address_space(1))) int *x);</div><div><br></div><div>At the end of ActOnFunctionDeclarator (right before the return) is where I have my check. </div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: #b731a1">for</span> (<span style="color: #b731a1">unsigned</span> <span style="color: #518187">p</span> = <span style="color: #2633d5">0</span>, <span style="color: #518187">NumParams</span> = NewFD-><span style="color: #33595d">getNumParams</span>(); </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">             <span style="color: #518187">p</span> < <span style="color: #518187">NumParams</span>; ++<span style="color: #518187">p</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">          <span style="color: #518187">ParmVarDecl</span> *<span style="color: #518187">Param</span> = NewFD-><span style="color: #33595d">getParamDecl</span>(<span style="color: #518187">p</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">          <span style="color: #518187">QualType</span> <span style="color: #518187">T</span> = <span style="color: #518187">Param</span>-><span style="color: #33595d">getType</span>();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">          <span style="color: #b731a1">if</span> (<span style="color: #518187">T</span>.<span style="color: #33595d">getAddressSpace</span>() == <span style="color: #2633d5">0</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">         </span>// do stuff</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">       </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">}</div></div><div><br></div><div>For some reason, getAddressSpace() is returning 0. </div><div><div><br></div><div>(gdb) p T.getAddressSpace()</div><div>$1 = 0</div><div>(gdb) p T.dump()</div><div>: int __attribute__((address_space(1)))*identifier</div><div>$2 = void</div></div></div></div></blockquote></div><br><div>The address space qualifier here applies to the "int", not to the "int*". If you get T as a PointerType (T->getAs<PointerType>()) and look at its pointee type, you'll see an address-space-qualified "int".</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">  </span>- Doug</div></body></html>