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