This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][MallocChecker] When modeling realloc-like functions, don't early return if the argument is symbolic
ClosedPublic

Authored by Szelethus on May 5 2020, 6:13 AM.

Details

Summary

The very essence of MallocChecker lies in 2 overload sets: the FreeMemAux functions and the MallocMemAux functions. The former houses most of the error checking as well (aside from leaks), such as incorrect deallocation. There, we check whether the argument's [[ https://clang.llvm.org/doxygen/classclang_1_1ento_1_1MemSpaceRegion.html | MemSpaceRegion]] is the heap or unknown, and if it isn't, we know we encountered a bug (aside from a corner case patched by @balazske in D76830), as specified by MEM34-C.

In ReallocMemAux, which really is the combination of FreeMemAux and MallocMemAux, we incorrectly early returned if the memory argument of realloc is non-symbolic. The problem is, one of the cases where this happens when we know precisely what the region is, like an array, as demonstrated in the test file. So, lets get rid of this false negative :^)

Side note, I dislike the warning message and the associated checker name, but I'll address it in a later patch.

Diff Detail

Event Timeline

Szelethus created this revision.May 5 2020, 6:13 AM
Szelethus edited the summary of this revision. (Show Details)May 5 2020, 6:19 AM
Szelethus edited the summary of this revision. (Show Details)
whisperity retitled this revision from [analyzer][MalloChecker] When modeling realloc-like functions, don't early return if the argument is symbolic to [analyzer][MallocChecker] When modeling realloc-like functions, don't early return if the argument is symbolic.May 6 2020, 5:08 AM
xazax.hun accepted this revision.May 6 2020, 5:25 AM

LGTM, thanks!

I do agree that the warning message is not the best but it is not horrible either :)

This revision is now accepted and ready to land.May 6 2020, 5:25 AM
This revision was automatically updated to reflect the committed changes.