[cfe-commits] r66842 - in /cfe/trunk/lib/Analysis: BugReporter.cpp ExplodedGraph.cpp
Ted Kremenek
kremenek at apple.com
Thu Mar 12 16:41:59 PDT 2009
Author: kremenek
Date: Thu Mar 12 18:41:59 2009
New Revision: 66842
URL: http://llvm.org/viewvc/llvm-project?rev=66842&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Analysis/BugReporter.cpp
cfe/trunk/lib/Analysis/ExplodedGraph.cpp
Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=66842&r1=66841&r2=66842&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu Mar 12 18:41:59 2009
@@ -24,6 +24,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
+#include <queue>
using namespace clang;
@@ -298,18 +299,19 @@
new ExplodedGraph<GRState>(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<const void*,unsigned> Visited;
- llvm::SmallVector<const ExplodedNode<GRState>*, 10> WS;
- WS.push_back(N);
+ std::queue<const ExplodedNode<GRState>*> WS;
+ WS.push(N);
+
unsigned cnt = 0;
const ExplodedNode<GRState>* Root = 0;
while (!WS.empty()) {
- const ExplodedNode<GRState>* Node = WS.back();
- WS.pop_back();
+ const ExplodedNode<GRState>* Node = WS.front();
+ WS.pop();
if (Visited.find(Node) != Visited.end())
continue;
@@ -323,12 +325,12 @@
for (ExplodedNode<GRState>::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<GRState> *Last = 0, *First = 0;
NodeBackMap *BM = new NodeBackMap();
Modified: cfe/trunk/lib/Analysis/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ExplodedGraph.cpp?rev=66842&r1=66841&r2=66842&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/ExplodedGraph.cpp Thu Mar 12 18:41:59 2009
@@ -18,7 +18,6 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>
-#include <list>
using namespace clang;
@@ -133,10 +132,9 @@
typedef llvm::DenseMap<const ExplodedNodeImpl*, ExplodedNodeImpl*> Pass2Ty;
Pass2Ty& Pass2 = M->M;
- std::list<const ExplodedNodeImpl*> WL1;
- llvm::SmallVector<const ExplodedNodeImpl*, 10> WL2;
+ llvm::SmallVector<const ExplodedNodeImpl*, 10> WL1, WL2;
- // ===- Pass 1 (reverse BFS) -===
+ // ===- Pass 1 (reverse DFS) -===
for (const ExplodedNodeImpl* const* I = BeginSources; I != EndSources; ++I) {
assert(*I);
WL1.push_back(*I);
@@ -163,7 +161,7 @@
// Visit our predecessors and enqueue them.
for (ExplodedNodeImpl** I=N->Preds.begin(), **E=N->Preds.end(); I!=E; ++I)
- WL1.push_front(*I);
+ WL1.push_back(*I);
}
// We didn't hit a root? Return with a null pointer for the new graph.
More information about the cfe-commits
mailing list