<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 6, 2016 at 3:09 AM, Apelete Seketeli <span dir="ltr"><<a href="mailto:apelete@seketeli.net" target="_blank">apelete@seketeli.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi David,<br>
<span><br>
On Thu, May-05-2016 at 11:20:06 AM -0700, David Blaikie wrote:<br>
> Hi Apelete,<br>
><br>
> Thanks for trying to help cleanup the LLVM codebase of Clang Static<br>
> Analyzer warnings.<br>
><br>
> But it seems a lot of the fixes that are being proposed are somewhat<br>
> mechanical and may be doing the wrong thing in a few ways.<br>
<br>
</span>From the beginning I wondered for each fix if it was the right way of<br>
solving the possible underlying issue pointed to by the Analyzer.<br>
Since I'm not familiar with the codebase, when I was not able to<br>
decide by reading the code I ended-up trusting the tool until advised<br>
otherwise by the reviewers.<br>
<br>
Once put together, the fixes do look somewhat mechanical indeed due to<br>
the fact that the same patterns were found throughout the codebase by<br>
the analyzer.<br>
As of this writing, these patterns result in 90+ warnings still<br>
emitted when scanning LLVM+Clang+Compiler-RT (down from 150+ warnings<br>
when I fooled myself into starting to look at it a few weeks ago).<br>
<br>
I'm glad you pointed out some of the patterns in the fixes, let's see<br>
how I can address those:<br>
<span><br>
> * Initializing variables that are only used when initialized through some<br>
> existing codepath - this can make tools like Memory Sanitizer less useful,<br>
> because now the value is initialized even in some path where that value is<br>
> never intended to be used<br>
<br>
</span>* I guess this case could be related to <a href="http://reviews.llvm.org/D19971" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19971</a><br>
  and <a href="http://reviews.llvm.org/D19975" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19975</a> for instance.<br>
  I wasn't happy with the fixes in the first place but I<br>
  ended-up trusting the tool because it proposed a codepath where the<br>
  variables were used without being initialized. I don't know about<br>
  msan (yet :) but if the warnings are false positives is there a way<br>
  to tell scan-build in such cases ?<br></blockquote><div><br></div><div>My first guess with any warning like this would be that there's some complex invariant (eg: A implies B, so if the variable is conditionally initialized under A then used under B it's actually fine) that is obvious enough in the code, but opaque to the static analyzer.<br><br>My first guess would be to assert this (assert the condition of A in the use under B) and only if we find a case where that fails, add a test case and initialize the variable as appropriate. Adding the variable initialization without a test case seems suspect.<br><br>MSan is a tool for dynamic analysis - it would track the uninitialized memory and tell us when/where we've used it without initializing it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> * Adding assertions for pointers that are known to be non-null - in some<br>
> cases this is helpful, when the algorithm that ensures the non-null-ness is<br>
> sufficiently opaque. But for function parameters - we have /lots/ of<br>
> non-null function parameters. I think it'd be impractical to assert on all<br>
> of them.<br>
<br>
</span>* This is where I ended-up asserting function parameters in a<br>
  mechanical manner to some extent (as a result of 40+ warnings about<br>
  some object pointers being null). Let's take <a href="http://reviews.llvm.org/D19385" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19385</a><br>
  for instance.<br>
  The right fix in that case was to pass the non-null parameter by<br>
  reference instead of asserting its value, not unlike what you were<br>
  discussing in the previous post (sorry I'm not quoting the right<br>
  post here). For the cases where using references might not be<br>
  possible, how do we deal with the warnings ?<br></blockquote><div><br></div><div>I think the tool needs to be fixed, or not used on the LLVM codebase if it assumes all pointer parameters may be null. But it seems like it doesn't assume that or I would expect way more errors from the tool, no? I was pretty sure the Clang Static Analyzer had been designed to only warn about null dereferences if it saw a pointer null test somewhere in the function for that pointer.<br><br>Do you know what's going on here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> But if we want to do something like this we should probably have some<br>
> community discussion about how how to go about any of these things across<br>
> the codebase. Maybe using nonnull attributes would be a better approach to<br>
> the parameter issue, for example - but it'll still be a lot of code churn<br>
> that there should probably be general consensus on rather than approaching<br>
> it piecemeal with reviewers in different parts of the codebase.<br>
<br>
</span>I agree we should discuss the bigger issue of how to deal with each<br>
type of warning emitted by Clang Static Analyzer. I would prefer to<br>
propose fixes that solve the underlying issues instead of just<br>
suppressing the warnings.<br>
<br>
Thanks again for taking the time to suggest a different approach.<br>
<br>
Cheers.<br>
<span><font color="#888888">--<br>
        Apelete<br>
</font></span></blockquote></div><br></div></div>