r176010 - [analyzer] add the notion of an "interesting" lvalue expression for ExplodedNode pruning.

Ted Kremenek kremenek at apple.com
Sun Feb 24 23:37:14 PST 2013


Author: kremenek
Date: Mon Feb 25 01:37:13 2013
New Revision: 176010

URL: http://llvm.org/viewvc/llvm-project?rev=176010&view=rev
Log:
[analyzer] add the notion of an "interesting" lvalue expression for ExplodedNode pruning.

r175988 modified the ExplodedGraph trimming algorithm to retain all
nodes for "lvalue" expressions.  This patch refines that notion to
only "interesting" expressions that would be used for diagnostics.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=176010&r1=176009&r2=176010&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h Mon Feb 25 01:37:13 2013
@@ -387,6 +387,10 @@ public:
   /// was called.
   void reclaimRecentlyAllocatedNodes();
 
+  /// \brief Returns true if nodes for the given expression kind are always
+  ///        kept around.
+  static bool isInterestingLValueExpr(const Expr *Ex);
+
 private:
   bool shouldCollect(const ExplodedNode *node);
   void collectNode(ExplodedNode *node);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=176010&r1=176009&r2=176010&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Feb 25 01:37:13 2013
@@ -663,7 +663,7 @@ bool bugreporter::trackNullOrUndefValue(
     // or function call inside.
     Ex = Ex->IgnoreParenCasts();
 
-    if (Ex->isLValue()) {
+    if (ExplodedGraph::isInterestingLValueExpr(Ex)) {
       const MemRegion *R = 0;
 
       // First check if this is a DeclRefExpr for a C++ reference type.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp?rev=176010&r1=176009&r2=176010&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp Mon Feb 25 01:37:13 2013
@@ -56,6 +56,14 @@ ExplodedGraph::~ExplodedGraph() {}
 // Node reclamation.
 //===----------------------------------------------------------------------===//
 
+bool ExplodedGraph::isInterestingLValueExpr(const Expr *Ex) {
+  if (!Ex->isLValue())
+    return false;
+  return isa<DeclRefExpr>(Ex) ||
+         isa<MemberExpr>(Ex) ||
+         isa<ObjCIvarRefExpr>(Ex);
+}
+
 bool ExplodedGraph::shouldCollect(const ExplodedNode *node) {
   // Reclaim all nodes that match *all* the following criteria:
   //
@@ -101,11 +109,15 @@ bool ExplodedGraph::shouldCollect(const
       progPoint.getLocationContext() != pred->getLocationContext())
     return false;
 
+  // All further checks require expressions.
+  const Expr *Ex = dyn_cast<Expr>(ps.getStmt());
+  if (!Ex)
+    return false;
+
   // Condition 8.
-  // Do not collect nodes for lvalue expressions since they are
+  // Do not collect nodes for "interesting" lvalue expressions since they are
   // used extensively for generating path diagnostics.
-  const Expr *Ex = dyn_cast<Expr>(ps.getStmt());
-  if (!Ex || Ex->isLValue())
+  if (isInterestingLValueExpr(Ex))
     return false;
 
   // Condition 9.





More information about the cfe-commits mailing list