<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 11, 2017 at 5:03 PM, Sven Verdoolaege <span dir="ltr"><<a href="mailto:skimo-cfe@kotnet.org" target="_blank">skimo-cfe@kotnet.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"><span class="gmail-">On Tue, Jul 11, 2017 at 10:33:06AM +0530, Malhar Thakkar wrote:<br>
> Hence, although evalCall() works perfectly for ISL, we may not be able to<br>
> generalize it for other C codebases.<br>
<br>
</span>I think it's reasonable to assume that frameworks that shield off<br>
free for reference counting, would also shield off malloc<br>
in order to initialize the reference counting.<br>
Of course, this may just be a lack of imagination on my part.<br>
Do you have any examples of frameworks that could use your<br>
annotations where this is not the case?<br></blockquote><div>Well, I haven't come across/thought of any such codebase which doesn't shield off malloc which is why I created a hypothetical test case. Now that you mention it, it does seem reasonable to assume that frameworks would shield off malloc as well. Also, keeping MallocChecker aside, there are a lot of other checkers which may create some issues if there are additional side-effects (as Dr. Artem mentioned) in such annotated functions. However, I guess it may be safe to assume that there are no such additional side-effects in such "trusted" functions.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
skimo<br></blockquote><div><br></div><div>Now, I was experimenting a bit more with evalCall-ing based on annotations and although this works like a charm for functions of the type obj_free() and obj_cow(), it is unable to avoid the problems created by obj_copy(). This is probably because of the lack of a core-foundation annotation which is analogous to isl_keep.<br></div><div>Consider the following example.</div><div><br></div><div><div></div><br><div><div class="gmail-hljs gmail-cpp" style="display:block;overflow-x:auto;padding:0.5em;background:rgb(248,248,248)"><div><font color="#1f7199" face="monospace">#define __isl_give __attribute__((cf_returns_retained))</font></div><div><font color="#1f7199" face="monospace">#define __isl_take __attribute__((cf_consumed))</font></div><div><font color="#1f7199" face="monospace">#define __isl_null</font></div><div><font color="#1f7199" face="monospace">#define __isl_keep</font></div><div><font color="#1f7199" face="monospace">#define NULL 0</font></div><div><font color="#1f7199" face="monospace"><br></font></div><div><font color="#1f7199" face="monospace">typedef struct</font></div><div><font color="#1f7199" face="monospace">{</font></div><div><font color="#1f7199" face="monospace">  int ref;</font></div><div><font color="#1f7199" face="monospace">} isl_basic_map;</font></div><div><font color="#1f7199" face="monospace"><br></font></div><div><font color="#1f7199" face="monospace">__isl_give isl_basic_map *isl_basic_map_cow(__isl_take isl_basic_map *bmap);</font></div><div><font color="#1f7199" face="monospace">__isl_null isl_basic_map *isl_basic_map_free(__isl_take isl_basic_map *bmap);</font></div><div><font color="#1f7199" face="monospace"><br></font></div><div><font color="#1f7199" face="monospace">__attribute__((annotate("rc_ownership_trusted_implementation"))) __isl_give isl_basic_map *isl_basic_map_copy(__isl_keep isl_basic_map *bmap)</font></div><div><font color="#1f7199" face="monospace">{</font></div><div><font color="#1f7199" face="monospace">  if (!bmap)</font></div><div><font color="#1f7199" face="monospace">    return NULL;</font></div><div><font color="#1f7199" face="monospace"><br></font></div><div><font color="#1f7199" face="monospace">  bmap->ref++;</font></div><div><font color="#1f7199" face="monospace">  return bmap;</font></div><div><font color="#1f7199" face="monospace">}</font></div><div><font color="#1f7199" face="monospace"><br></font></div><div><font color="#1f7199" face="monospace">void test_use_after_release_with_trusted_implementation_annotate_attribute(__isl_take isl_basic_map *bmap) {</font></div><div><font color="#1f7199" face="monospace">  bmap = isl_basic_map_cow(bmap);</font></div><div><font color="#1f7199" face="monospace">  isl_basic_map *temp = isl_basic_map_cow(isl_basic_map_copy(bmap)); <b>// Here, the analyzer states "Object released".</b></font></div><div><font color="#1f7199" face="monospace">  isl_basic_map *temp2 = isl_basic_map_cow(bmap); <b>// Use-after-release for 'bmap' raised here.</b></font></div><div><font color="#1f7199" face="monospace">  isl_basic_map_free(temp2);</font></div><div><font color="#1f7199" face="monospace">  isl_basic_map_free(temp);</font></div><div><font color="#1f7199" face="monospace">}</font></div></div></div><br><div></div></div><div>Hence, I need more clarity as to what assumptions the checker/analyzer makes when it doesn't see any annotation associated with an object.</div><div><br></div><div><br></div><div>Regards,</div><div>Malhar</div><div><br></div><div><br></div></div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=e37e26b8-ced2-47be-b834-053c626e0744"><font color="#ffffff" size="1">ᐧ</font></div>