<div dir="ltr">Patch to fix this is in review at <a href="http://reviews.llvm.org/D15324">http://reviews.llvm.org/D15324</a> . It should be able to catch simple cases like the one you posted.<div><br></div><div>Thanks for catching this! :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 6:47 AM, Xavier Chantry 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clang 3.6 brought some very useful warnings when a function argument with __attribute__((nonnull)) had a NULL check:<br>
warning: nonnull parameter 'p' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]<br>
<br>
With gcc and earlier clang versions, the NULL check was silently optimized away.<br>
<br>
We just realized that the same problem remains with __attribute__((returns_nonnull)): NULL checks are silently optimized away, as in the following test case.<br>
<br>
int *nul(void) {<br>
return NULL;<br>
}<br>
<br>
__attribute__((returns_nonnull)) int *foo(void)<br>
{<br>
return nul();<br>
}<br>
<br>
int main(void)<br>
{<br>
fprintf(stderr, "%p\n", foo());<br>
if (foo() == NULL) {<br>
fprintf(stderr, "foo is null\n");<br>
}<br>
return 0;<br>
}<br>
<br>
Is it planned to have a warning in that case ?<br>
_______________________________________________<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/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>