[cfe-commits] r167316 - /cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp

Anna Zaks ganna at apple.com
Fri Nov 2 14:30:04 PDT 2012


Author: zaks
Date: Fri Nov  2 16:30:04 2012
New Revision: 167316

URL: http://llvm.org/viewvc/llvm-project?rev=167316&view=rev
Log:
[analyzer] Factor SimpleStreamChecker pulling out isLeaked().

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp?rev=167316&r1=167315&r2=167316&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp Fri Nov  2 16:30:04 2012
@@ -136,29 +136,35 @@
   C.addTransition(State);
 }
 
+static bool isLeaked(SymbolRef Sym, const StreamState &SS,
+                     bool IsSymDead, ProgramStateRef State) {
+  if (IsSymDead && SS.isOpened()) {
+    // If a symbol is NULL, assume that fopen failed on this path.
+    // A symbol should only be considered leaked if it is non-null.
+    ConstraintManager &CMgr = State->getConstraintManager();
+    ConditionTruthVal OpenFailed = CMgr.isNull(State, Sym);
+    return !OpenFailed.isConstrainedTrue();
+  }
+  return false;
+}
+
 void SimpleStreamChecker::checkDeadSymbols(SymbolReaper &SymReaper,
                                            CheckerContext &C) const {
   ProgramStateRef State = C.getState();
-  StreamMapTy TrackedStreams = State->get<StreamMap>();
-
   SymbolVector LeakedStreams;
+  StreamMapTy TrackedStreams = State->get<StreamMap>();
   for (StreamMapTy::iterator I = TrackedStreams.begin(),
                              E = TrackedStreams.end(); I != E; ++I) {
     SymbolRef Sym = I->first;
-    if (SymReaper.isDead(Sym)) {
-      const StreamState &SS = I->second;
-      if (SS.isOpened()) {
-        // If a symbol is NULL, assume that fopen failed on this path
-        // and do not report a leak.
-        ConstraintManager &CMgr = State->getConstraintManager();
-        ConditionTruthVal OpenFailed = CMgr.isNull(State, Sym);
-        if (!OpenFailed.isConstrainedTrue())
-          LeakedStreams.push_back(Sym);
-      }
+    bool IsSymDead = SymReaper.isDead(Sym);
+
+    // Collect leaked symbols.
+    if (isLeaked(Sym, I->second, IsSymDead, State))
+      LeakedStreams.push_back(Sym);
 
-      // Remove the dead symbol from the streams map.
+    // Remove the dead symbol from the streams map.
+    if (IsSymDead)
       State = State->remove<StreamMap>(Sym);
-    }
   }
 
   ExplodedNode *N = C.addTransition(State);





More information about the cfe-commits mailing list