Skip to content

Commit

Permalink
[analyzer] MallocChecker: Avoid redundant transitions.
Browse files Browse the repository at this point in the history
Don't generate a checker-tagged node unconditionally on the first
checkDeadSymbols callback when no pointers are tracked.

This is a tiny performance optimization; it may change the behavior slightly
by making Static Analyzer bail out on max-nodes one node later (which is good)
but any test would either break for no good reason or become useless
every time someone sneezes.

Differential Revision: https://reviews.llvm.org/D54013

llvm-svn: 347955
  • Loading branch information
haoNoQ committed Nov 30, 2018
1 parent 34d3576 commit e2b5438
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
Expand Up @@ -2346,20 +2346,29 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
CheckerContext &C) const
{
ProgramStateRef state = C.getState();
RegionStateTy RS = state->get<RegionState>();
RegionStateTy OldRS = state->get<RegionState>();
RegionStateTy::Factory &F = state->get_context<RegionState>();

RegionStateTy RS = OldRS;
SmallVector<SymbolRef, 2> Errors;
for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) {
if (SymReaper.isDead(I->first)) {
if (I->second.isAllocated() || I->second.isAllocatedOfSizeZero())
Errors.push_back(I->first);
// Remove the dead symbol from the map.
RS = F.remove(RS, I->first);

}
}

if (RS == OldRS) {
// We shouldn't have touched other maps yet.
assert(state->get<ReallocPairs>() ==
C.getState()->get<ReallocPairs>());
assert(state->get<FreeReturnValue>() ==
C.getState()->get<FreeReturnValue>());
return;
}

// Cleanup the Realloc Pairs Map.
ReallocPairsTy RP = state->get<ReallocPairs>();
for (ReallocPairsTy::iterator I = RP.begin(), E = RP.end(); I != E; ++I) {
Expand Down

0 comments on commit e2b5438

Please sign in to comment.