This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash
AbandonedPublic

Authored by martong on Sep 16 2020, 12:11 PM.

Details

Summary

It could happen that both the satisfied and unsatisfied constraints gave
a NULL state. This happened probably because the negate() functionality
was not perfect. The solution is to return both states from the assume
calls where it makes sense.
This way the code becomes cleaner, there is no need anymore for the
controversial negate().

Note that this causes a regression in our CTU builds.
http://codechecker-buildbot.eastus.cloudapp.azure.com:8080/job/ctu_pipeline_clang-master-monorepo/1720/
The error itself is not CTU related, however, the coverage and thus the path is different in that mode.

Diff Detail

Event Timeline

martong created this revision.Sep 16 2020, 12:11 PM
martong requested review of this revision.Sep 16 2020, 12:11 PM
martong added inline comments.Sep 16 2020, 12:13 PM
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
725

This is where we crashed before this fix.

steakhal added inline comments.Sep 16 2020, 12:53 PM
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
235–247

I suggest the same simpler version for the similar code segments as well.

By the same token, why do you return {State, State}?
Shouldn't you return {State, nullptr} there?
In general, one would not expect the same State being returned, IMO it's advised to avoid doing that.
Same applies for the other cases.

339–340

Why don't you castAs? That also has the corresponding assert inside.

martong updated this revision to Diff 292550.Sep 17 2020, 10:01 AM
  • apply -> assume, Add isApplicable

Alright, I refactored the change a bit. A Constraint::assume works similarly to an engine DualAssume. Plus I added isApplicable to check if it is meaningful to call the assume at all.

martong abandoned this revision.Sep 21 2020, 2:25 AM
martong added inline comments.
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
725

assert(SuccessSt); should not ever fail. Seems like the logic is not flawed in negate rather there is an issue in the underlying RangeConstraintManager: the analyzer goes on with an unfeasible path.

See the post-commit comments here: https://reviews.llvm.org/D82445