[PATCH] D54013: [analyzer] MallocChecker: Avoid redundant transitions.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 1 17:04:54 PDT 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, rnkovacs.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, szepet, baloghadamsoftware.

In its `checkDeadSymbols` callback, when no pointers are tracked and the state is not updated, `MallocChecker` would update the state from "the map of symbols is unset" to "the map of symbols is set to an empty map", which generates a redundant exploded node. Now that zombie symbols are fixed in https://reviews.llvm.org/D18860, we would call `checkDeadSymbols()` with no dead symbols more often. Avoid the unnecessary transition here.


Repository:
  rC Clang

https://reviews.llvm.org/D54013

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp


Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2366,9 +2366,10 @@
                                      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)) {
@@ -2376,10 +2377,12 @@
         Errors.push_back(I->first);
       // Remove the dead symbol from the map.
       RS = F.remove(RS, I->first);
-
     }
   }
 
+  if (RS == OldRS)
+    return;
+
   // Cleanup the Realloc Pairs Map.
   ReallocPairsTy RP = state->get<ReallocPairs>();
   for (ReallocPairsTy::iterator I = RP.begin(), E = RP.end(); I != E; ++I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54013.172273.patch
Type: text/x-patch
Size: 1063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181102/05054bef/attachment.bin>


More information about the cfe-commits mailing list