This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][solver] Prevent infeasible states (PR49490)
ClosedPublic

Authored by vsavchenko on Mar 10 2021, 5:57 AM.

Details

Summary

This patch fixes the situation when our knowledge of disequalities
can help us figuring out that some assumption is infeasible, but
the solver still produces a state with inconsistent constraints.

Additionally, this patch adds a couple of assertions to catch this
type of problems easier.

Diff Detail

Event Timeline

vsavchenko created this revision.Mar 10 2021, 5:57 AM
vsavchenko requested review of this revision.Mar 10 2021, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2021, 5:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NoQ accepted this revision.Mar 10 2021, 8:42 AM

You're testing it with the help of an alpha checker. Is this checker doing something special that we don't do normally? In particular, both array bound checkers that we have are very likely to be re-done from scratch if they are ever to be completed. A lot of decisions in them are questionable. So i'm worried that this test will become stale in that process. Maybe a unittest would be more appropriate so that to guarantee the specific functionality without relying on implementation details of the specific checker(?)

Code looks great and I guess assertions are a test on their own.

This revision is now accepted and ready to land.Mar 10 2021, 8:42 AM
steakhal accepted this revision.Mar 11 2021, 2:58 AM

Looks good btw.

clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
1400–1406

inline is unnecessary. All member functions are inline by default.
I would take the parameter by const ref in the lambda.
Why did you mark it LLVM_ATTRIBUTE_UNUSED ? LLVM_NODISCARD would be probably a better choice.

Fix review comments

vsavchenko marked an inline comment as done.Mar 11 2021, 3:14 AM
vsavchenko added inline comments.
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
1400–1406

Fair point about inline.
LLVM_NODISCARD doesn't exclude LLVM_ATTRIBUTE_UNUSED.
It should be marked that way for Release builds when compiler might figure out that this class is local to only this TU, and this function is not used here anywhere. You can see in the comment for this macro that this is actually the main motivation for this macro to be used.

vsavchenko marked an inline comment as done.

Make areFeasible function static

steakhal added inline comments.Mar 11 2021, 4:53 AM
clang/test/Analysis/PR49490.cpp
13

I think you can remove this line.
We already have a global variable to be invalidated by the evaluation of oob_access() call.

Remove unused global variable from the test

vsavchenko marked an inline comment as done.Mar 11 2021, 4:58 AM
This revision was landed with ongoing or failed builds.Mar 12 2021, 4:57 AM
This revision was automatically updated to reflect the committed changes.

The assertion areFeasible(Constraints) triggered on trunk.
More details in the Bugzilla ticket.