<div dir="ltr">Hi <span style="font-size:12.8px">Gábor,</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">This setting helps. But I have a follow up question. Is it possible to treat return from 'int main(int argc, char* argv[])' as a sink just like the [[noreturn]] functions?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">For example, like the previous example,</span></div><div><span style="font-size:12.8px"><br></span></div><div><div style="font-size:12.8px"><div><font face="monospace, monospace">typedef uint32_t mx_handle_t;</font></div><div><font face="monospace, monospace">typedef int32_t mx_status_t;</font></div></div><div style="font-size:12.8px"><font face="monospace, monospace"><br></font></div><div style="font-size:12.8px"><div><font face="monospace, monospace">mx_status_t mx_channel_create(</font></div><div><font face="monospace, monospace">uint32_t options,</font></div><div><font face="monospace, monospace">mx_handle_t* out0,</font></div><div><font face="monospace, monospace">mx_handle_t* out1);</font></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div><font face="monospace, monospace">int main(int argc, char* argv[]) {</font></div><div><font face="monospace, monospace">  mx_handle_t sa, sb;</font></div><div><font face="monospace, monospace">  mx_channel_create(0, &sa, &sb);</font></div><div><font face="monospace, monospace">  //...</font></div><div><font face="monospace, monospace">  return 0;</font></div><div><font face="monospace, monospace">}</font></div></div></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The program will quit if it returns from main and it would not be very helpful to report these leaks as well.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks,</span></div><div><span style="font-size:12.8px">Haowei</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 1, 2017 at 2:55 AM, Gábor Horváth <span dir="ltr"><<a href="mailto:xazax.hun@gmail.com" target="_blank">xazax.hun@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi Haowei!<br><br></div>There is a heuristic already in the analyzer to suppress such cases. There is a method in BugType called setSuppressOnSink. Could you check if setting this to true would help?<br><br></div>Regards,<br></div>Gábor<br><div><div><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 31 July 2017 at 19:51, Haowei Wu 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></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>I am working on a checker and I would like to suppress bug reports when a path reached a function with [[noreturn]] attribute. For example:</div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">typedef uint32_t mx_handle_t;</font></div><div><font face="monospace, monospace">typedef int32_t mx_status_t;</font></div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">mx_status_t mx_channel_create(</font></div><div><font face="monospace, monospace">uint32_t options,</font></div><div><font face="monospace, monospace">mx_handle_t* out0,</font></div><div><font face="monospace, monospace">mx_handle_t* out1);</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">[[noreturn]] void noreturnFunc();<br></font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">void checkNoReturn() {</font></div><div><font face="monospace, monospace">  mx_handle_t sa, sb;</font></div><div><font face="monospace, monospace">  mx_channel_create(0, &sa, &sb);</font></div><div><font face="monospace, monospace">  //...</font></div><div><font face="monospace, monospace">  noreturnFunc();</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>Function <font face="monospace, monospace">mx_channel_create</font> will allocate two handles(file descriptors) and save them to '<font face="monospace, monospace">sa</font>' and '<font face="monospace, monospace">sb</font>'. Since there is no other call to release these two handles, the checker will report them as leaked. But in this special case, there is a call to '<font face="monospace, monospace">noreturnFunc</font>()' which will terminate the process and leaked handles will be recycled by the OS so it is may not necessary to report these bugs. The source code of the checker can be found in D35968, D36022, D36023, D36<wbr>024.</div><div><br></div><div>My first thought is that I can use REGISTER_TRAIT_WITHPROGRAMSTAT<wbr>E macro to add a bool flag in the ProgramState and this flag will be set if the <font face="monospace, monospace">FunctionDecl->isNoReturn()</font> returns true in the <font face="monospace, monospace">evalCall</font> callback. Then in the <font face="monospace, monospace">checkDeadSymbols</font> callback, do not report any leaked symbols if the flag registered through REGISTER_TRAIT_WITHPROGRAMSTAT<wbr>E is set. However, I did some experiment and found out that in the code example, the symbols in '<font face="monospace, monospace">sa</font>' and '<font face="monospace, monospace">sb</font>' were dead in the <font face="monospace, monospace">checkDeadSymbols</font> before the <font face="monospace, monospace">evalCall</font> on '<font face="monospace, monospace">noreturnFunc</font>' was invoked. Further experiment showed that the <font face="monospace, monospace">checkDeadSymbols</font> on '<font face="monospace, monospace">sa</font>' and '<font face="monospace, monospace">sb</font>' was invoked even before <font face="monospace, monospace">checkPreStmt(const CallExpr *, CheckerContext &)</font> callback. So this solution does not work.</div><div><br></div><div>Is there anything I can do in the checker to solve this problem?</div><div><br></div><div>Thanks for any help.</div><span class="m_3367466528899949390HOEnZb"><font color="#888888"><div><br></div><div>Haowei</div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>