diff options
| author | Ted Kremenek <kremenek@apple.com> | 2013-02-25 07:37:13 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2013-02-25 07:37:13 +0000 |
| commit | 04fa9e3d80a9bfff23e373af329f3c655bc4ee29 (patch) | |
| tree | 0a0d78db49fc102af35dbffadd2aa53104e8f410 /clang | |
| parent | 87869db5f5394fc35f38de1ebbe85f21d5549d99 (diff) | |
| download | bcm5719-llvm-04fa9e3d80a9bfff23e373af329f3c655bc4ee29.tar.gz bcm5719-llvm-04fa9e3d80a9bfff23e373af329f3c655bc4ee29.zip | |
[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.
llvm-svn: 176010
Diffstat (limited to 'clang')
3 files changed, 20 insertions, 4 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index 82ac3d9ed06..70be1f8c639 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -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); diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index cb716a31548..5e3daff9a45 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -663,7 +663,7 @@ bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, // 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. diff --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index 443d87076a3..02268c410ab 100644 --- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -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 ExplodedNode *node) { 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. |

