This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] A quick fix on top of D12901/r257464
ClosedPublic

Authored by NoQ on Jan 14 2016, 2:42 AM.

Details

Summary

Sorry for being a bit slow, i should have had a look at the review earlier; i noticed some stuff after the recent patch by Pierre Gousseau was committed.

  1. There's an off-by-one in the comparison evalBinOp in evalIntegralCast, the patch attached to this revision fixes it, and tests it via bool-assignment checker.
  1. There's also a FIXME test for the same checker, which is a regression after this patch (used to throw a warning, now it doesn't); seems not as bad as the crash, so it can probably be addressed later.
  1. I noticed that it's still possible to trigger the crash with the following test, not sure what to do with it:
void f1(long foo)
{
  unsigned index = -1;
  if (index < foo - 1) index = foo;
  if (index + 1 == 0) {}
}

So my best idea is to push this quick fix for off-by-one and then think where to go further. Probably we need to teach RangeConstraintManager to work with SymbolCast's correctly (eg. understand how their range is related to a parent symbol's range). Eventually, once it gets better, we'd probably want to change the following in evalIntegralCast:

   std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
-  if (!IsNotTruncated && IsTruncated) {
+  if (IsTruncated) {

but right now it breaks tests (not only bool-assignment, but also other checkers that start failing can probably be shown to loose warnings after this patch, but i didn't have a look at this yet, so not sure, just hand-waving).

Anyway, generally, overally, i think r257464 is a step in the very right direction if we want to work with casts better, and i was actually very happy to see it went that way :)

Diff Detail

Repository
rL LLVM

Event Timeline

NoQ updated this revision to Diff 44842.Jan 14 2016, 2:42 AM
NoQ retitled this revision from to [analyzer] A quick fix on top of D12901/r257464.
NoQ updated this object.
NoQ added a subscriber: cfe-commits.
pgousseau accepted this revision.Jan 14 2016, 4:53 AM
pgousseau edited edge metadata.

LGTM!
Thanks Artom for finding the bug and new test case, sorry for missing those in my patch!
Removing "!IsNotTruncated" is definitely worth trying.
Please commit if code owners are happy with it too.

Pierre.

This revision is now accepted and ready to land.Jan 14 2016, 4:53 AM
zaks.anna accepted this revision.Jan 15 2016, 4:42 PM
zaks.anna edited edge metadata.
This revision was automatically updated to reflect the committed changes.