From 10aa55410bbecbb658ce14a5f801d50cf06d12df Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 12 Mar 2009 23:41:59 +0000 Subject: Use the correct data structures! ExplodedGraph::TrimGraph: - Just do a DFS both ways instead of BFS-DFS. We're just determining what subset of the nodes are reachable from the root and reverse-reachable from the bug nodes. DFS is more efficient for this task. BugReporter: - MakeReportGraph: Do a reverse-BFS instead of a reverse-DFS to determine the approximate shortest path through the simulation graph. We were seeing some weird cases where too many loops were being reported for simple bugs. Possibly we will need to replace this with actually computing the shortest path in terms of line numbers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66842 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BugReporter.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/Analysis/BugReporter.cpp') diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index 8719be7fdd..ffa1593fd5 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" +#include using namespace clang; @@ -298,18 +299,19 @@ MakeReportGraph(const ExplodedGraph* G, new ExplodedGraph(GTrim->getCFG(), GTrim->getCodeDecl(), GTrim->getContext()); - // Sometimes the trimmed graph can contain a cycle. Perform a reverse DFS + // Sometimes the trimmed graph can contain a cycle. Perform a reverse BFS // to the root node, and then construct a new graph that contains only // a single path. llvm::DenseMap Visited; - llvm::SmallVector*, 10> WS; - WS.push_back(N); + std::queue*> WS; + WS.push(N); + unsigned cnt = 0; const ExplodedNode* Root = 0; while (!WS.empty()) { - const ExplodedNode* Node = WS.back(); - WS.pop_back(); + const ExplodedNode* Node = WS.front(); + WS.pop(); if (Visited.find(Node) != Visited.end()) continue; @@ -323,12 +325,12 @@ MakeReportGraph(const ExplodedGraph* G, for (ExplodedNode::const_pred_iterator I=Node->pred_begin(), E=Node->pred_end(); I!=E; ++I) - WS.push_back(*I); + WS.push(*I); } assert (Root); - // Now walk from the root down the DFS path, always taking the successor + // Now walk from the root down the BFS path, always taking the successor // with the lowest number. ExplodedNode *Last = 0, *First = 0; NodeBackMap *BM = new NodeBackMap(); -- cgit v1.2.3-18-g5258