From a28565ac6280c981afc54027ef9902a54dceed23 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 16 May 2009 01:11:58 +0000 Subject: [PATCH] Fix another bug in BugReporter where we wouldn't always select the bug report in a bug equivalence class with the shortest path. llvm-svn: 71920 --- clang/lib/Analysis/BugReporter.cpp | 34 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp index eedc18f56df6..32998e1c4256 100644 --- a/clang/lib/Analysis/BugReporter.cpp +++ b/clang/lib/Analysis/BugReporter.cpp @@ -1347,16 +1347,19 @@ MakeReportGraph(const ExplodedGraph* G, // Find the (first) error node in the trimmed graph. We just need to consult // the node map (NMap) which maps from nodes in the original graph to nodes // in the new graph. - const ExplodedNode* N = 0; - unsigned NodeIndex = 0; + + std::queue*> WS; + typedef llvm::DenseMap*,unsigned> IndexMapTy; + IndexMapTy IndexMap; for (const ExplodedNode** I = NStart; I != NEnd; ++I) - if ((N = NMap->getMappedNode(*I))) { - NodeIndex = (I - NStart) / sizeof(*I); - break; + if (const ExplodedNode *N = NMap->getMappedNode(*I)) { + unsigned NodeIndex = (I - NStart) / sizeof(*I); + WS.push(N); + IndexMap[*I] = NodeIndex; } - assert(N && "No error node found in the trimmed graph."); + assert(!WS.empty() && "No error node found in the trimmed graph."); // Create a new (third!) graph with a single path. This is the graph // that will be returned to the caller. @@ -1368,8 +1371,6 @@ MakeReportGraph(const ExplodedGraph* G, // to the root node, and then construct a new graph that contains only // a single path. llvm::DenseMap Visited; - std::queue*> WS; - WS.push(N); unsigned cnt = 0; const ExplodedNode* Root = 0; @@ -1393,17 +1394,18 @@ MakeReportGraph(const ExplodedGraph* G, WS.push(*I); } - assert (Root); + assert(Root); // 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(); + unsigned NodeIndex = 0; - for ( N = Root ;;) { + for ( const ExplodedNode *N = Root ;;) { // Lookup the number associated with the current node. llvm::DenseMap::iterator I = Visited.find(N); - assert (I != Visited.end()); + assert(I != Visited.end()); // Create the equivalent node in the new graph with the same state // and location. @@ -1422,8 +1424,11 @@ MakeReportGraph(const ExplodedGraph* G, Last = NewN; // Are we at the final node? - if (I->second == 0) { + IndexMapTy::iterator IMI = + IndexMap.find((const ExplodedNode*)(IMitr->second)); + if (IMI != IndexMap.end()) { First = NewN; + NodeIndex = IMI->second; break; } @@ -1446,10 +1451,11 @@ MakeReportGraph(const ExplodedGraph* G, } } - assert (N); + assert(N); } - assert (First); + assert(First); + return std::make_pair(std::make_pair(GNew, BM), std::make_pair(First, NodeIndex)); }