<br><br><div class="gmail_quote">On Tue, Jun 29, 2010 at 1:27 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Jun 28, 2010, at 6:16 PM, Andrew McGregor wrote:<br>
<br>
> Hmm, but which is cleaner and clearer... have the checker know that arguments might be attributed as well, or have the parser push attributes from arguments onto the function?  The latter is probably less code, but might be rather obscure.  On the other hand, that whole attribute parser is pretty obscure, and is full of 'fixme's saying it deserves redesigned.<br>

><br>
<br>
<br>
</div>I don't think we want to duplicate attributes; attributes on the ParmVarDecls should only be on the ParmVarDecls, unless of course we want to incorporate the the attributes into the function's type.  The AST should have high fidelity to the actual source code.<br>

<br>
That said, I don't think the checker should be in the business of having to reason about how the function was annotated.  The checker just cares about the semantics, while it's up to the parser and the attributes to handle the syntax.<br>

<br>
One possible solution is to provide a static function(s) to OwnershipAttr et al that allows one to query a FunctionDecl for the relevant annotations.  Then the checker just cares if a parameter is annotated, but it doesn't care how it was written.</blockquote>
</div><br><div>So, thinking about this led me to this idea:</div><div><br></div><div>These attributes actually have minimal differences so far as the checker is concerned.  So how about there being only one attribute object  type, probably an OwnershipAttr, with an enum kind embedded in it, that can be applied to an argument.  Each one would apply to just one argument or the return value, but may have several arguments (the so far unimplemented calloc case will need this, as will pointer-to-pointer malloc).  The parser would have to construct two attribute objects for __attribute((ownership_holds, 1, 2)).  That way the dispatch can be a case statement on the enum rather than the current mess of casts and tests.  This would also save some of the methods from being templates, which I think would be unnecessary complexity.</div>
<div><br></div><div>Or, again in order to reduce the duplication, I could make templates of some of the methods and use the type to represent the attribute kind the same way as I have so far.  Disadvantage: this is probably going to bloat.</div>
<div><br></div><div>Andrew</div>