From 09ed9617ba51e2f83d3d566e6c0b2376eb86c804 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Fri, 30 Nov 2018 03:52:42 +0000 Subject: [PATCH] [analyzer] MallocChecker: Avoid redundant transitions. 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347955 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index ded355e899..c2b4e130f3 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2346,9 +2346,10 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const { ProgramStateRef state = C.getState(); - RegionStateTy RS = state->get(); + RegionStateTy OldRS = state->get(); RegionStateTy::Factory &F = state->get_context(); + RegionStateTy RS = OldRS; SmallVector Errors; for (RegionStateTy::iterator I = RS.begin(), E = RS.end(); I != E; ++I) { if (SymReaper.isDead(I->first)) { @@ -2356,10 +2357,18 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper, 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() == + C.getState()->get()); + assert(state->get() == + C.getState()->get()); + return; + } + // Cleanup the Realloc Pairs Map. ReallocPairsTy RP = state->get(); for (ReallocPairsTy::iterator I = RP.begin(), E = RP.end(); I != E; ++I) { -- 2.50.1