Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 1 | // BugReporter.cpp - Generate PathDiagnostics for Bugs ------------*- C++ -*--// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines BugReporter, a utility class for generating |
| 11 | // PathDiagnostics for analyses based on GRSimpleVals. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Analysis/PathSensitive/BugReporter.h" |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/PathSensitive/GRExprEngine.h" |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 17 | #include "clang/Basic/SourceManager.h" |
| 18 | #include "clang/Basic/SourceLocation.h" |
| 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/CFG.h" |
| 21 | #include "clang/AST/Expr.h" |
| 22 | #include "clang/Analysis/ProgramPoint.h" |
| 23 | #include "clang/Analysis/PathDiagnostic.h" |
Chris Lattner | 405674c | 2008-08-23 22:23:37 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/DenseMap.h" |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/STLExtras.h" |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace clang; |
| 29 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
| 31 | // static functions. |
| 32 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 33 | |
| 34 | static inline Stmt* GetStmt(const ProgramPoint& P) { |
| 35 | if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) { |
| 36 | return PS->getStmt(); |
| 37 | } |
| 38 | else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) { |
| 39 | return BE->getSrc()->getTerminator(); |
| 40 | } |
| 41 | else if (const BlockEntrance* BE = dyn_cast<BlockEntrance>(&P)) { |
| 42 | return BE->getFirstStmt(); |
| 43 | } |
| 44 | |
| 45 | assert (false && "Unsupported ProgramPoint."); |
| 46 | return NULL; |
| 47 | } |
| 48 | |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 49 | static inline Stmt* GetStmt(const CFGBlock* B) { |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 50 | if (B->empty()) |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 51 | return const_cast<Stmt*>(B->getTerminator()); |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 52 | else |
| 53 | return (*B)[0]; |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 56 | static inline const ExplodedNode<GRState>* |
| 57 | GetNextNode(const ExplodedNode<GRState>* N) { |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 58 | return N->pred_empty() ? NULL : *(N->pred_begin()); |
| 59 | } |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 60 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 61 | static Stmt* GetLastStmt(const ExplodedNode<GRState>* N) { |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 62 | assert (isa<BlockEntrance>(N->getLocation())); |
| 63 | |
| 64 | for (N = GetNextNode(N); N; N = GetNextNode(N)) { |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 65 | ProgramPoint P = N->getLocation(); |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 66 | if (PostStmt* PS = dyn_cast<PostStmt>(&P)) return PS->getStmt(); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | return NULL; |
| 70 | } |
| 71 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 72 | static inline Stmt* GetStmt(const ExplodedNode<GRState>* N) { |
| 73 | ProgramPoint ProgP = N->getLocation(); |
| 74 | return isa<BlockEntrance>(ProgP) ? GetLastStmt(N) : GetStmt(ProgP); |
| 75 | } |
| 76 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 77 | static void ExecutionContinues(llvm::raw_string_ostream& os, |
| 78 | SourceManager& SMgr, |
| 79 | const Stmt* S) { |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 80 | if (!S) |
| 81 | return; |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 82 | |
| 83 | // Slow, but probably doesn't matter. |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 84 | if (os.str().empty()) os << ' '; |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 85 | |
| 86 | os << "Execution continues on line " |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 87 | << SMgr.getInstantiationLineNumber(S->getLocStart()) << '.'; |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 88 | } |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 89 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 90 | static inline void ExecutionContinues(llvm::raw_string_ostream& os, |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 91 | SourceManager& SMgr, |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 92 | const ExplodedNode<GRState>* N) { |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 93 | ExecutionContinues(os, SMgr, GetStmt(N->getLocation())); |
| 94 | } |
| 95 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 96 | static inline void ExecutionContinues(llvm::raw_string_ostream& os, |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 97 | SourceManager& SMgr, |
| 98 | const CFGBlock* B) { |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 99 | ExecutionContinues(os, SMgr, GetStmt(B)); |
| 100 | } |
| 101 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 102 | //===----------------------------------------------------------------------===// |
| 103 | // Methods for BugType and subclasses. |
| 104 | //===----------------------------------------------------------------------===// |
| 105 | BugType::~BugType() {} |
| 106 | void BugType::FlushReports(BugReporter &BR) {} |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 107 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 108 | //===----------------------------------------------------------------------===// |
| 109 | // Methods for BugReport and subclasses. |
| 110 | //===----------------------------------------------------------------------===// |
| 111 | BugReport::~BugReport() {} |
| 112 | RangedBugReport::~RangedBugReport() {} |
| 113 | |
| 114 | Stmt* BugReport::getStmt(BugReporter& BR) const { |
Ted Kremenek | 200ed92 | 2008-05-02 23:21:21 +0000 | [diff] [blame] | 115 | ProgramPoint ProgP = EndNode->getLocation(); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 116 | Stmt *S = NULL; |
| 117 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 118 | if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) { |
| 119 | if (BE->getBlock() == &BR.getCFG()->getExit()) S = GetLastStmt(EndNode); |
| 120 | } |
| 121 | if (!S) S = GetStmt(ProgP); |
| 122 | |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 123 | return S; |
| 124 | } |
| 125 | |
| 126 | PathDiagnosticPiece* |
| 127 | BugReport::getEndPath(BugReporter& BR, |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 128 | const ExplodedNode<GRState>* EndPathNode) { |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 129 | |
| 130 | Stmt* S = getStmt(BR); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 131 | |
| 132 | if (!S) |
| 133 | return NULL; |
| 134 | |
Ted Kremenek | c9fa2f7 | 2008-05-01 23:13:35 +0000 | [diff] [blame] | 135 | FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager()); |
| 136 | PathDiagnosticPiece* P = new PathDiagnosticPiece(L, getDescription()); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 137 | |
Ted Kremenek | de7161f | 2008-04-03 18:00:37 +0000 | [diff] [blame] | 138 | const SourceRange *Beg, *End; |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 139 | getRanges(BR, Beg, End); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 140 | |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 141 | for (; Beg != End; ++Beg) |
| 142 | P->addRange(*Beg); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 143 | |
| 144 | return P; |
| 145 | } |
| 146 | |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 147 | void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg, |
| 148 | const SourceRange*& end) { |
| 149 | |
| 150 | if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) { |
| 151 | R = E->getSourceRange(); |
| 152 | beg = &R; |
| 153 | end = beg+1; |
| 154 | } |
| 155 | else |
| 156 | beg = end = 0; |
Ted Kremenek | f1ae705 | 2008-04-03 17:57:38 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 159 | SourceLocation BugReport::getLocation() const { |
| 160 | if (EndNode) |
| 161 | if (Stmt* S = GetStmt(EndNode)) |
| 162 | return S->getLocStart(); |
| 163 | |
| 164 | return FullSourceLoc(); |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 167 | PathDiagnosticPiece* BugReport::VisitNode(const ExplodedNode<GRState>* N, |
| 168 | const ExplodedNode<GRState>* PrevN, |
| 169 | const ExplodedGraph<GRState>& G, |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 170 | BugReporter& BR, |
| 171 | NodeResolver &NR) { |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 172 | return NULL; |
| 173 | } |
| 174 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 175 | //===----------------------------------------------------------------------===// |
| 176 | // Methods for BugReporter and subclasses. |
| 177 | //===----------------------------------------------------------------------===// |
| 178 | |
| 179 | BugReportEquivClass::~BugReportEquivClass() { |
| 180 | for (iterator I=begin(), E=end(); I!=E; ++I) delete *I; |
| 181 | } |
| 182 | |
| 183 | GRBugReporter::~GRBugReporter() { FlushReports(); } |
| 184 | BugReporterData::~BugReporterData() {} |
| 185 | |
| 186 | ExplodedGraph<GRState>& |
| 187 | GRBugReporter::getGraph() { return Eng.getGraph(); } |
| 188 | |
| 189 | GRStateManager& |
| 190 | GRBugReporter::getStateManager() { return Eng.getStateManager(); } |
| 191 | |
| 192 | BugReporter::~BugReporter() { FlushReports(); } |
| 193 | |
| 194 | void BugReporter::FlushReports() { |
| 195 | if (BugTypes.isEmpty()) |
| 196 | return; |
| 197 | |
| 198 | // First flush the warnings for each BugType. This may end up creating new |
| 199 | // warnings and new BugTypes. Because ImmutableSet is a functional data |
| 200 | // structure, we do not need to worry about the iterators being invalidated. |
| 201 | for (BugTypesTy::iterator I=BugTypes.begin(), E=BugTypes.end(); I!=E; ++I) |
| 202 | const_cast<BugType*>(*I)->FlushReports(*this); |
| 203 | |
| 204 | // Iterate through BugTypes a second time. BugTypes may have been updated |
| 205 | // with new BugType objects and new warnings. |
| 206 | for (BugTypesTy::iterator I=BugTypes.begin(), E=BugTypes.end(); I!=E; ++I) { |
| 207 | BugType *BT = const_cast<BugType*>(*I); |
| 208 | |
| 209 | typedef llvm::FoldingSet<BugReportEquivClass> SetTy; |
| 210 | SetTy& EQClasses = BT->EQClasses; |
| 211 | |
| 212 | for (SetTy::iterator EI=EQClasses.begin(), EE=EQClasses.end(); EI!=EE;++EI){ |
| 213 | BugReportEquivClass& EQ = *EI; |
| 214 | FlushReport(EQ); |
| 215 | } |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 216 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 217 | // Delete the BugType object. This will also delete the equivalence |
| 218 | // classes. |
| 219 | delete BT; |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 220 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 221 | |
| 222 | // Remove all references to the BugType objects. |
| 223 | BugTypes = F.GetEmptySet(); |
| 224 | } |
| 225 | |
| 226 | //===----------------------------------------------------------------------===// |
| 227 | // PathDiagnostics generation. |
| 228 | //===----------------------------------------------------------------------===// |
| 229 | |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 230 | typedef llvm::DenseMap<const ExplodedNode<GRState>*, |
| 231 | const ExplodedNode<GRState>*> NodeBackMap; |
| 232 | |
| 233 | static std::pair<std::pair<ExplodedGraph<GRState>*, NodeBackMap*>, |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 234 | std::pair<ExplodedNode<GRState>*, unsigned> > |
| 235 | MakeReportGraph(const ExplodedGraph<GRState>* G, |
| 236 | const ExplodedNode<GRState>** NStart, |
| 237 | const ExplodedNode<GRState>** NEnd) { |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 238 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 239 | // Create the trimmed graph. It will contain the shortest paths from the |
| 240 | // error nodes to the root. In the new graph we should only have one |
| 241 | // error node unless there are two or more error nodes with the same minimum |
| 242 | // path length. |
| 243 | ExplodedGraph<GRState>* GTrim; |
| 244 | InterExplodedGraphMap<GRState>* NMap; |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 245 | |
| 246 | llvm::DenseMap<const void*, const void*> InverseMap; |
| 247 | llvm::tie(GTrim, NMap) = G->Trim(NStart, NEnd, &InverseMap); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 248 | |
| 249 | // Create owning pointers for GTrim and NMap just to ensure that they are |
| 250 | // released when this function exists. |
| 251 | llvm::OwningPtr<ExplodedGraph<GRState> > AutoReleaseGTrim(GTrim); |
| 252 | llvm::OwningPtr<InterExplodedGraphMap<GRState> > AutoReleaseNMap(NMap); |
| 253 | |
| 254 | // Find the (first) error node in the trimmed graph. We just need to consult |
| 255 | // the node map (NMap) which maps from nodes in the original graph to nodes |
| 256 | // in the new graph. |
| 257 | const ExplodedNode<GRState>* N = 0; |
| 258 | unsigned NodeIndex = 0; |
| 259 | |
| 260 | for (const ExplodedNode<GRState>** I = NStart; I != NEnd; ++I) |
| 261 | if ((N = NMap->getMappedNode(*I))) { |
| 262 | NodeIndex = (I - NStart) / sizeof(*I); |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | assert(N && "No error node found in the trimmed graph."); |
| 267 | |
| 268 | // Create a new (third!) graph with a single path. This is the graph |
| 269 | // that will be returned to the caller. |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 270 | ExplodedGraph<GRState> *GNew = |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 271 | new ExplodedGraph<GRState>(GTrim->getCFG(), GTrim->getCodeDecl(), |
| 272 | GTrim->getContext()); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 273 | |
| 274 | // Sometimes the trimmed graph can contain a cycle. Perform a reverse DFS |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 275 | // to the root node, and then construct a new graph that contains only |
| 276 | // a single path. |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 277 | llvm::DenseMap<const void*,unsigned> Visited; |
| 278 | llvm::SmallVector<const ExplodedNode<GRState>*, 10> WS; |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 279 | WS.push_back(N); |
| 280 | unsigned cnt = 0; |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 281 | const ExplodedNode<GRState>* Root = 0; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 282 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 283 | while (!WS.empty()) { |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 284 | const ExplodedNode<GRState>* Node = WS.back(); |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 285 | WS.pop_back(); |
| 286 | |
| 287 | if (Visited.find(Node) != Visited.end()) |
| 288 | continue; |
| 289 | |
| 290 | Visited[Node] = cnt++; |
| 291 | |
| 292 | if (Node->pred_empty()) { |
| 293 | Root = Node; |
| 294 | break; |
| 295 | } |
| 296 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 297 | for (ExplodedNode<GRState>::const_pred_iterator I=Node->pred_begin(), |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 298 | E=Node->pred_end(); I!=E; ++I) |
| 299 | WS.push_back(*I); |
| 300 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 301 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 302 | assert (Root); |
| 303 | |
| 304 | // Now walk from the root down the DFS path, always taking the successor |
| 305 | // with the lowest number. |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 306 | ExplodedNode<GRState> *Last = 0, *First = 0; |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 307 | NodeBackMap *BM = new NodeBackMap(); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 308 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 309 | for ( N = Root ;;) { |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 310 | // Lookup the number associated with the current node. |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 311 | llvm::DenseMap<const void*,unsigned>::iterator I = Visited.find(N); |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 312 | assert (I != Visited.end()); |
| 313 | |
| 314 | // Create the equivalent node in the new graph with the same state |
| 315 | // and location. |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 316 | ExplodedNode<GRState>* NewN = |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 317 | GNew->getNode(N->getLocation(), N->getState()); |
| 318 | |
| 319 | // Store the mapping to the original node. |
| 320 | llvm::DenseMap<const void*, const void*>::iterator IMitr=InverseMap.find(N); |
| 321 | assert(IMitr != InverseMap.end() && "No mapping to original node."); |
| 322 | (*BM)[NewN] = (const ExplodedNode<GRState>*) IMitr->second; |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 323 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 324 | // Link up the new node with the previous node. |
| 325 | if (Last) |
| 326 | NewN->addPredecessor(Last); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 327 | |
| 328 | Last = NewN; |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 329 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 330 | // Are we at the final node? |
| 331 | if (I->second == 0) { |
| 332 | First = NewN; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 333 | break; |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 334 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 335 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 336 | // Find the next successor node. We choose the node that is marked |
| 337 | // with the lowest DFS number. |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 338 | ExplodedNode<GRState>::const_succ_iterator SI = N->succ_begin(); |
| 339 | ExplodedNode<GRState>::const_succ_iterator SE = N->succ_end(); |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 340 | N = 0; |
| 341 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 342 | for (unsigned MinVal = 0; SI != SE; ++SI) { |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 343 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 344 | I = Visited.find(*SI); |
| 345 | |
| 346 | if (I == Visited.end()) |
| 347 | continue; |
| 348 | |
| 349 | if (!N || I->second < MinVal) { |
| 350 | N = *SI; |
| 351 | MinVal = I->second; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 352 | } |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 353 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 354 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 355 | assert (N); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 356 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 357 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame] | 358 | assert (First); |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 359 | return std::make_pair(std::make_pair(GNew, BM), |
| 360 | std::make_pair(First, NodeIndex)); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 363 | static const VarDecl* |
| 364 | GetMostRecentVarDeclBinding(const ExplodedNode<GRState>* N, |
| 365 | GRStateManager& VMgr, SVal X) { |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 366 | |
| 367 | for ( ; N ; N = N->pred_empty() ? 0 : *N->pred_begin()) { |
| 368 | |
| 369 | ProgramPoint P = N->getLocation(); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 370 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 371 | if (!isa<PostStmt>(P)) |
| 372 | continue; |
| 373 | |
| 374 | DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt()); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 375 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 376 | if (!DR) |
| 377 | continue; |
| 378 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 379 | SVal Y = VMgr.GetSVal(N->getState(), DR); |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 380 | |
| 381 | if (X != Y) |
| 382 | continue; |
| 383 | |
| 384 | VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()); |
| 385 | |
| 386 | if (!VD) |
| 387 | continue; |
| 388 | |
| 389 | return VD; |
| 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 395 | namespace { |
| 396 | class VISIBILITY_HIDDEN NotableSymbolHandler |
| 397 | : public StoreManager::BindingsHandler { |
| 398 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 399 | SymbolRef Sym; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 400 | const GRState* PrevSt; |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 401 | const Stmt* S; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 402 | GRStateManager& VMgr; |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 403 | const ExplodedNode<GRState>* Pred; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 404 | PathDiagnostic& PD; |
| 405 | BugReporter& BR; |
| 406 | |
| 407 | public: |
| 408 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 409 | NotableSymbolHandler(SymbolRef sym, const GRState* prevst, const Stmt* s, |
| 410 | GRStateManager& vmgr, const ExplodedNode<GRState>* pred, |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 411 | PathDiagnostic& pd, BugReporter& br) |
| 412 | : Sym(sym), PrevSt(prevst), S(s), VMgr(vmgr), Pred(pred), PD(pd), BR(br) {} |
| 413 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 414 | bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal V) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 415 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 416 | SymbolRef ScanSym; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 417 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 418 | if (loc::SymbolVal* SV = dyn_cast<loc::SymbolVal>(&V)) |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 419 | ScanSym = SV->getSymbol(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 420 | else if (nonloc::SymbolVal* SV = dyn_cast<nonloc::SymbolVal>(&V)) |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 421 | ScanSym = SV->getSymbol(); |
| 422 | else |
| 423 | return true; |
| 424 | |
| 425 | if (ScanSym != Sym) |
| 426 | return true; |
| 427 | |
| 428 | // Check if the previous state has this binding. |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 429 | SVal X = VMgr.GetSVal(PrevSt, loc::MemRegionVal(R)); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 430 | |
| 431 | if (X == V) // Same binding? |
| 432 | return true; |
| 433 | |
| 434 | // Different binding. Only handle assignments for now. We don't pull |
| 435 | // this check out of the loop because we will eventually handle other |
| 436 | // cases. |
| 437 | |
| 438 | VarDecl *VD = 0; |
| 439 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 440 | if (const BinaryOperator* B = dyn_cast<BinaryOperator>(S)) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 441 | if (!B->isAssignmentOp()) |
| 442 | return true; |
| 443 | |
| 444 | // What variable did we assign to? |
| 445 | DeclRefExpr* DR = dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParenCasts()); |
| 446 | |
| 447 | if (!DR) |
| 448 | return true; |
| 449 | |
| 450 | VD = dyn_cast<VarDecl>(DR->getDecl()); |
| 451 | } |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 452 | else if (const DeclStmt* DS = dyn_cast<DeclStmt>(S)) { |
Ted Kremenek | f21a4b4 | 2008-10-06 18:37:46 +0000 | [diff] [blame] | 453 | // FIXME: Eventually CFGs won't have DeclStmts. Right now we |
| 454 | // assume that each DeclStmt has a single Decl. This invariant |
| 455 | // holds by contruction in the CFG. |
| 456 | VD = dyn_cast<VarDecl>(*DS->decl_begin()); |
| 457 | } |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 458 | |
| 459 | if (!VD) |
| 460 | return true; |
| 461 | |
| 462 | // What is the most recently referenced variable with this binding? |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 463 | const VarDecl* MostRecent = GetMostRecentVarDeclBinding(Pred, VMgr, V); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 464 | |
| 465 | if (!MostRecent) |
| 466 | return true; |
| 467 | |
| 468 | // Create the diagnostic. |
| 469 | |
| 470 | FullSourceLoc L(S->getLocStart(), BR.getSourceManager()); |
| 471 | |
| 472 | if (VD->getType()->isPointerLikeType()) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 473 | std::string msg = "'" + std::string(VD->getNameAsString()) + |
| 474 | "' now aliases '" + MostRecent->getNameAsString() + "'"; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 475 | |
| 476 | PD.push_front(new PathDiagnosticPiece(L, msg)); |
| 477 | } |
| 478 | |
| 479 | return true; |
| 480 | } |
| 481 | }; |
| 482 | } |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 483 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 484 | static void HandleNotableSymbol(const ExplodedNode<GRState>* N, |
| 485 | const Stmt* S, |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 486 | SymbolRef Sym, BugReporter& BR, |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 487 | PathDiagnostic& PD) { |
| 488 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 489 | const ExplodedNode<GRState>* Pred = N->pred_empty() ? 0 : *N->pred_begin(); |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 490 | const GRState* PrevSt = Pred ? Pred->getState() : 0; |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 491 | |
| 492 | if (!PrevSt) |
| 493 | return; |
| 494 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 495 | // Look at the region bindings of the current state that map to the |
| 496 | // specified symbol. Are any of them not in the previous state? |
Ted Kremenek | 4adc81e | 2008-08-13 04:27:00 +0000 | [diff] [blame] | 497 | GRStateManager& VMgr = cast<GRBugReporter>(BR).getStateManager(); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 498 | NotableSymbolHandler H(Sym, PrevSt, S, VMgr, Pred, PD, BR); |
| 499 | cast<GRBugReporter>(BR).getStateManager().iterBindings(N->getState(), H); |
| 500 | } |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 501 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 502 | namespace { |
| 503 | class VISIBILITY_HIDDEN ScanNotableSymbols |
| 504 | : public StoreManager::BindingsHandler { |
| 505 | |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 506 | llvm::SmallSet<SymbolRef, 10> AlreadyProcessed; |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 507 | const ExplodedNode<GRState>* N; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 508 | Stmt* S; |
| 509 | GRBugReporter& BR; |
| 510 | PathDiagnostic& PD; |
| 511 | |
| 512 | public: |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 513 | ScanNotableSymbols(const ExplodedNode<GRState>* n, Stmt* s, GRBugReporter& br, |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 514 | PathDiagnostic& pd) |
| 515 | : N(n), S(s), BR(br), PD(pd) {} |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 516 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 517 | bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal V) { |
Ted Kremenek | 2dabd43 | 2008-12-05 02:27:51 +0000 | [diff] [blame] | 518 | SymbolRef ScanSym; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 519 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 520 | if (loc::SymbolVal* SV = dyn_cast<loc::SymbolVal>(&V)) |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 521 | ScanSym = SV->getSymbol(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 522 | else if (nonloc::SymbolVal* SV = dyn_cast<nonloc::SymbolVal>(&V)) |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 523 | ScanSym = SV->getSymbol(); |
| 524 | else |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 525 | return true; |
| 526 | |
| 527 | assert (ScanSym.isInitialized()); |
| 528 | |
| 529 | if (!BR.isNotable(ScanSym)) |
| 530 | return true; |
| 531 | |
| 532 | if (AlreadyProcessed.count(ScanSym)) |
| 533 | return true; |
| 534 | |
| 535 | AlreadyProcessed.insert(ScanSym); |
| 536 | |
| 537 | HandleNotableSymbol(N, S, ScanSym, BR, PD); |
| 538 | return true; |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 539 | } |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 540 | }; |
| 541 | } // end anonymous namespace |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 542 | |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 543 | namespace { |
| 544 | class VISIBILITY_HIDDEN NodeMapClosure : public BugReport::NodeResolver { |
| 545 | NodeBackMap& M; |
| 546 | public: |
| 547 | NodeMapClosure(NodeBackMap *m) : M(*m) {} |
| 548 | ~NodeMapClosure() {} |
| 549 | |
| 550 | const ExplodedNode<GRState>* getOriginalNode(const ExplodedNode<GRState>* N) { |
| 551 | NodeBackMap::iterator I = M.find(N); |
| 552 | return I == M.end() ? 0 : I->second; |
| 553 | } |
| 554 | }; |
| 555 | } |
| 556 | |
Ted Kremenek | c095997 | 2008-07-02 21:24:01 +0000 | [diff] [blame] | 557 | void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 558 | BugReportEquivClass& EQ) { |
| 559 | |
| 560 | std::vector<const ExplodedNode<GRState>*> Nodes; |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 561 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 562 | for (BugReportEquivClass::iterator I=EQ.begin(), E=EQ.end(); I!=E; ++I) { |
| 563 | const ExplodedNode<GRState>* N = I->getEndNode(); |
| 564 | if (N) Nodes.push_back(N); |
| 565 | } |
| 566 | |
| 567 | if (Nodes.empty()) |
| 568 | return; |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 569 | |
| 570 | // Construct a new graph that contains only a single path from the error |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 571 | // node to a root. |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 572 | const std::pair<std::pair<ExplodedGraph<GRState>*, NodeBackMap*>, |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 573 | std::pair<ExplodedNode<GRState>*, unsigned> >& |
| 574 | GPair = MakeReportGraph(&getGraph(), &Nodes[0], &Nodes[0] + Nodes.size()); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 575 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 576 | // Find the BugReport with the original location. |
| 577 | BugReport *R = 0; |
| 578 | unsigned i = 0; |
| 579 | for (BugReportEquivClass::iterator I=EQ.begin(), E=EQ.end(); I!=E; ++I, ++i) |
| 580 | if (i == GPair.second.second) { R = *I; break; } |
| 581 | |
| 582 | assert(R && "No original report found for sliced graph."); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 583 | |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 584 | llvm::OwningPtr<ExplodedGraph<GRState> > ReportGraph(GPair.first.first); |
| 585 | llvm::OwningPtr<NodeBackMap> BackMap(GPair.first.second); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 586 | const ExplodedNode<GRState> *N = GPair.second.first; |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 587 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 588 | // Start building the path diagnostic... |
| 589 | if (PathDiagnosticPiece* Piece = R->getEndPath(*this, N)) |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 590 | PD.push_back(Piece); |
| 591 | else |
| 592 | return; |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 593 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 594 | const ExplodedNode<GRState>* NextNode = N->pred_empty() |
| 595 | ? NULL : *(N->pred_begin()); |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 596 | |
Ted Kremenek | c095997 | 2008-07-02 21:24:01 +0000 | [diff] [blame] | 597 | ASTContext& Ctx = getContext(); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 598 | SourceManager& SMgr = Ctx.getSourceManager(); |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 599 | NodeMapClosure NMC(BackMap.get()); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 600 | |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 601 | while (NextNode) { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 602 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 603 | const ExplodedNode<GRState>* LastNode = N; |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 604 | N = NextNode; |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 605 | NextNode = GetNextNode(N); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 606 | |
| 607 | ProgramPoint P = N->getLocation(); |
| 608 | |
| 609 | if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) { |
| 610 | |
| 611 | CFGBlock* Src = BE->getSrc(); |
| 612 | CFGBlock* Dst = BE->getDst(); |
| 613 | |
| 614 | Stmt* T = Src->getTerminator(); |
| 615 | |
| 616 | if (!T) |
| 617 | continue; |
| 618 | |
| 619 | FullSourceLoc L(T->getLocStart(), SMgr); |
| 620 | |
| 621 | switch (T->getStmtClass()) { |
| 622 | default: |
| 623 | break; |
| 624 | |
| 625 | case Stmt::GotoStmtClass: |
| 626 | case Stmt::IndirectGotoStmtClass: { |
| 627 | |
| 628 | Stmt* S = GetStmt(LastNode->getLocation()); |
| 629 | |
| 630 | if (!S) |
| 631 | continue; |
| 632 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 633 | std::string sbuf; |
| 634 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 635 | |
| 636 | os << "Control jumps to line " |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 637 | << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 638 | |
| 639 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 640 | break; |
| 641 | } |
| 642 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 643 | case Stmt::SwitchStmtClass: { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 644 | // Figure out what case arm we took. |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 645 | std::string sbuf; |
| 646 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 647 | |
| 648 | if (Stmt* S = Dst->getLabel()) |
| 649 | switch (S->getStmtClass()) { |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 650 | default: |
Ted Kremenek | 3ddc4d5 | 2008-12-20 01:41:43 +0000 | [diff] [blame] | 651 | os << "No cases match in the switch statement. " |
| 652 | "Control jumps to line " |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 653 | << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 654 | break; |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 655 | case Stmt::DefaultStmtClass: |
| 656 | os << "Control jumps to the 'default' case at line " |
| 657 | << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n"; |
| 658 | break; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 659 | |
| 660 | case Stmt::CaseStmtClass: { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 661 | os << "Control jumps to 'case "; |
| 662 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 663 | CaseStmt* Case = cast<CaseStmt>(S); |
| 664 | Expr* LHS = Case->getLHS()->IgnoreParenCasts(); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 665 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 666 | // Determine if it is an enum. |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 667 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 668 | bool GetRawInt = true; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 669 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 670 | if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS)) { |
| 671 | |
| 672 | // FIXME: Maybe this should be an assertion. Are there cases |
| 673 | // were it is not an EnumConstantDecl? |
Chris Lattner | 470e5fc | 2008-11-18 06:07:40 +0000 | [diff] [blame] | 674 | EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(DR->getDecl()); |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 675 | if (D) { |
| 676 | GetRawInt = false; |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 677 | os << D->getNameAsString(); |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 678 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 679 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 680 | |
| 681 | if (GetRawInt) { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 682 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 683 | // Not an enum. |
| 684 | Expr* CondE = cast<SwitchStmt>(T)->getCond(); |
| 685 | unsigned bits = Ctx.getTypeSize(CondE->getType()); |
| 686 | llvm::APSInt V(bits, false); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 687 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 688 | if (!LHS->isIntegerConstantExpr(V, Ctx, 0, true)) { |
| 689 | assert (false && "Case condition must be constant."); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 690 | continue; |
| 691 | } |
| 692 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 693 | os << V; |
| 694 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 695 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 696 | os << ":' at line " |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 697 | << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 698 | |
| 699 | break; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
Ted Kremenek | 5678392 | 2008-04-25 01:29:56 +0000 | [diff] [blame] | 702 | else { |
Ted Kremenek | c3517eb | 2008-09-12 18:17:46 +0000 | [diff] [blame] | 703 | os << "'Default' branch taken. "; |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 704 | ExecutionContinues(os, SMgr, LastNode); |
Ted Kremenek | 5678392 | 2008-04-25 01:29:56 +0000 | [diff] [blame] | 705 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 706 | |
| 707 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 708 | break; |
| 709 | } |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 710 | |
| 711 | case Stmt::BreakStmtClass: |
| 712 | case Stmt::ContinueStmtClass: { |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 713 | std::string sbuf; |
| 714 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 715 | ExecutionContinues(os, SMgr, LastNode); |
| 716 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 717 | break; |
| 718 | } |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 719 | |
| 720 | case Stmt::ConditionalOperatorClass: { |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 721 | std::string sbuf; |
| 722 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 723 | os << "'?' condition evaluates to "; |
| 724 | |
| 725 | if (*(Src->succ_begin()+1) == Dst) |
| 726 | os << "false."; |
| 727 | else |
| 728 | os << "true."; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 729 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 730 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 731 | break; |
| 732 | } |
| 733 | |
| 734 | case Stmt::DoStmtClass: { |
| 735 | |
| 736 | if (*(Src->succ_begin()) == Dst) { |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 737 | std::string sbuf; |
| 738 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 739 | |
Ted Kremenek | c3517eb | 2008-09-12 18:17:46 +0000 | [diff] [blame] | 740 | os << "Loop condition is true. "; |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 741 | ExecutionContinues(os, SMgr, Dst); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 742 | |
| 743 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 744 | } |
| 745 | else |
| 746 | PD.push_front(new PathDiagnosticPiece(L, |
| 747 | "Loop condition is false. Exiting loop.")); |
| 748 | |
| 749 | break; |
| 750 | } |
| 751 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 752 | case Stmt::WhileStmtClass: |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 753 | case Stmt::ForStmtClass: { |
| 754 | |
| 755 | if (*(Src->succ_begin()+1) == Dst) { |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 756 | std::string sbuf; |
| 757 | llvm::raw_string_ostream os(sbuf); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 758 | |
Ted Kremenek | c3517eb | 2008-09-12 18:17:46 +0000 | [diff] [blame] | 759 | os << "Loop condition is false. "; |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 760 | ExecutionContinues(os, SMgr, Dst); |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 761 | |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 762 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 763 | } |
| 764 | else |
| 765 | PD.push_front(new PathDiagnosticPiece(L, |
| 766 | "Loop condition is true. Entering loop body.")); |
| 767 | |
| 768 | break; |
| 769 | } |
| 770 | |
Ted Kremenek | 297308e | 2009-02-10 23:56:07 +0000 | [diff] [blame] | 771 | case Stmt::IfStmtClass: { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 772 | if (*(Src->succ_begin()+1) == Dst) |
| 773 | PD.push_front(new PathDiagnosticPiece(L, "Taking false branch.")); |
| 774 | else |
| 775 | PD.push_front(new PathDiagnosticPiece(L, "Taking true branch.")); |
| 776 | |
| 777 | break; |
| 778 | } |
| 779 | } |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 780 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 781 | |
Ted Kremenek | fe9e543 | 2009-02-18 03:48:14 +0000 | [diff] [blame] | 782 | if (PathDiagnosticPiece* p = R->VisitNode(N, NextNode, *ReportGraph, *this, |
| 783 | NMC)) |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 784 | PD.push_front(p); |
| 785 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 786 | if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) { |
| 787 | // Scan the region bindings, and see if a "notable" symbol has a new |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 788 | // lval binding. |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 789 | ScanNotableSymbols SNS(N, PS->getStmt(), *this, PD); |
| 790 | getStateManager().iterBindings(N->getState(), SNS); |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 791 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 795 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 796 | void BugReporter::Register(BugType *BT) { |
| 797 | BugTypes = F.Add(BugTypes, BT); |
Ted Kremenek | 76d90c8 | 2008-05-16 18:33:14 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 800 | void BugReporter::EmitReport(BugReport* R) { |
| 801 | // Compute the bug report's hash to determine its equivalence class. |
| 802 | llvm::FoldingSetNodeID ID; |
| 803 | R->Profile(ID); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 804 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 805 | // Lookup the equivance class. If there isn't one, create it. |
| 806 | BugType& BT = R->getBugType(); |
| 807 | Register(&BT); |
| 808 | void *InsertPos; |
| 809 | BugReportEquivClass* EQ = BT.EQClasses.FindNodeOrInsertPos(ID, InsertPos); |
| 810 | |
| 811 | if (!EQ) { |
| 812 | EQ = new BugReportEquivClass(R); |
| 813 | BT.EQClasses.InsertNode(EQ, InsertPos); |
| 814 | } |
| 815 | else |
| 816 | EQ->AddReport(R); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 819 | void BugReporter::FlushReport(BugReportEquivClass& EQ) { |
| 820 | assert(!EQ.Reports.empty()); |
| 821 | BugReport &R = **EQ.begin(); |
| 822 | |
| 823 | // FIXME: Make sure we use the 'R' for the path that was actually used. |
| 824 | // Probably doesn't make a difference in practice. |
| 825 | BugType& BT = R.getBugType(); |
| 826 | |
| 827 | llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getBugType().getName(), |
| 828 | R.getDescription(), |
| 829 | BT.getCategory())); |
| 830 | GeneratePathDiagnostic(*D.get(), EQ); |
Ted Kremenek | 072192b | 2008-04-30 23:47:44 +0000 | [diff] [blame] | 831 | |
| 832 | // Get the meta data. |
Ted Kremenek | 072192b | 2008-04-30 23:47:44 +0000 | [diff] [blame] | 833 | std::pair<const char**, const char**> Meta = R.getExtraDescriptiveText(); |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 834 | for (const char** s = Meta.first; s != Meta.second; ++s) D->addMeta(*s); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 835 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 836 | // Emit a summary diagnostic to the regular Diagnostics engine. |
Ted Kremenek | c095997 | 2008-07-02 21:24:01 +0000 | [diff] [blame] | 837 | PathDiagnosticClient* PD = getPathDiagnosticClient(); |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 838 | const SourceRange *Beg = 0, *End = 0; |
| 839 | R.getRanges(*this, Beg, End); |
| 840 | Diagnostic& Diag = getDiagnostic(); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 841 | FullSourceLoc L(R.getLocation(), getSourceManager()); |
Ted Kremenek | d90e708 | 2009-02-07 22:36:41 +0000 | [diff] [blame] | 842 | unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning, |
| 843 | R.getDescription().c_str()); |
Ted Kremenek | 5720207 | 2008-07-14 17:40:50 +0000 | [diff] [blame] | 844 | |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 845 | switch (End-Beg) { |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 846 | default: assert(0 && "Don't handle this many ranges yet!"); |
| 847 | case 0: Diag.Report(L, ErrorDiag); break; |
| 848 | case 1: Diag.Report(L, ErrorDiag) << Beg[0]; break; |
| 849 | case 2: Diag.Report(L, ErrorDiag) << Beg[0] << Beg[1]; break; |
| 850 | case 3: Diag.Report(L, ErrorDiag) << Beg[0] << Beg[1] << Beg[2]; break; |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 851 | } |
Ted Kremenek | 3148eb4 | 2009-01-24 00:55:43 +0000 | [diff] [blame] | 852 | |
| 853 | // Emit a full diagnostic for the path if we have a PathDiagnosticClient. |
| 854 | if (!PD) |
| 855 | return; |
| 856 | |
| 857 | if (D->empty()) { |
| 858 | PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription()); |
| 859 | for ( ; Beg != End; ++Beg) piece->addRange(*Beg); |
| 860 | D->push_back(piece); |
| 861 | } |
| 862 | |
| 863 | PD->HandlePathDiagnostic(D.take()); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 864 | } |
Ted Kremenek | 5720207 | 2008-07-14 17:40:50 +0000 | [diff] [blame] | 865 | |
Ted Kremenek | 8c036c7 | 2008-09-20 04:23:38 +0000 | [diff] [blame] | 866 | void BugReporter::EmitBasicReport(const char* name, const char* str, |
| 867 | SourceLocation Loc, |
| 868 | SourceRange* RBeg, unsigned NumRanges) { |
| 869 | EmitBasicReport(name, "", str, Loc, RBeg, NumRanges); |
| 870 | } |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 871 | |
Ted Kremenek | 8c036c7 | 2008-09-20 04:23:38 +0000 | [diff] [blame] | 872 | void BugReporter::EmitBasicReport(const char* name, const char* category, |
| 873 | const char* str, SourceLocation Loc, |
| 874 | SourceRange* RBeg, unsigned NumRanges) { |
| 875 | |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 876 | // 'BT' will be owned by BugReporter as soon as we call 'EmitReport'. |
| 877 | BugType *BT = new BugType(name, category); |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 878 | FullSourceLoc L = getContext().getFullLoc(Loc); |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 879 | RangedBugReport *R = new DiagBugReport(*BT, str, L); |
| 880 | for ( ; NumRanges > 0 ; --NumRanges, ++RBeg) R->addRange(*RBeg); |
| 881 | EmitReport(R); |
Ted Kremenek | 5720207 | 2008-07-14 17:40:50 +0000 | [diff] [blame] | 882 | } |