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" |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 24 | #include "llvm/ADT/DenseMap.h" |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 25 | #include <sstream> |
| 26 | |
| 27 | using namespace clang; |
| 28 | |
| 29 | BugReporter::~BugReporter() {} |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 30 | BugType::~BugType() {} |
| 31 | BugReport::~BugReport() {} |
Ted Kremenek | 5e55cda | 2008-04-11 18:40:29 +0000 | [diff] [blame] | 32 | RangedBugReport::~RangedBugReport() {} |
| 33 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 34 | ExplodedGraph<ValueState>& BugReporter::getGraph() { |
| 35 | return Eng.getGraph(); |
| 36 | } |
| 37 | |
| 38 | ValueStateManager& BugReporter::getStateManager() { |
| 39 | return Eng.getStateManager(); |
| 40 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 41 | |
| 42 | static inline Stmt* GetStmt(const ProgramPoint& P) { |
| 43 | if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) { |
| 44 | return PS->getStmt(); |
| 45 | } |
| 46 | else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) { |
| 47 | return BE->getSrc()->getTerminator(); |
| 48 | } |
| 49 | else if (const BlockEntrance* BE = dyn_cast<BlockEntrance>(&P)) { |
| 50 | return BE->getFirstStmt(); |
| 51 | } |
| 52 | |
| 53 | assert (false && "Unsupported ProgramPoint."); |
| 54 | return NULL; |
| 55 | } |
| 56 | |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 57 | static inline Stmt* GetStmt(const CFGBlock* B) { |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 58 | if (B->empty()) |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 59 | return const_cast<Stmt*>(B->getTerminator()); |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 60 | else |
| 61 | return (*B)[0]; |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 64 | static inline ExplodedNode<ValueState>* |
| 65 | GetNextNode(ExplodedNode<ValueState>* N) { |
| 66 | return N->pred_empty() ? NULL : *(N->pred_begin()); |
| 67 | } |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 68 | |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 69 | static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) { |
| 70 | assert (isa<BlockEntrance>(N->getLocation())); |
| 71 | |
| 72 | for (N = GetNextNode(N); N; N = GetNextNode(N)) { |
| 73 | |
| 74 | ProgramPoint P = N->getLocation(); |
| 75 | |
| 76 | if (PostStmt* PS = dyn_cast<PostStmt>(&P)) |
| 77 | return PS->getStmt(); |
| 78 | } |
| 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 83 | static void ExecutionContinues(std::ostringstream& os, SourceManager& SMgr, |
| 84 | Stmt* S) { |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 85 | |
| 86 | if (!S) |
| 87 | return; |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 88 | |
| 89 | // Slow, but probably doesn't matter. |
| 90 | if (os.str().empty()) |
| 91 | os << ' '; |
| 92 | |
| 93 | os << "Execution continues on line " |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 94 | << SMgr.getLogicalLineNumber(S->getLocStart()) << '.'; |
| 95 | } |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | static inline void ExecutionContinues(std::ostringstream& os, |
| 99 | SourceManager& SMgr, |
| 100 | ExplodedNode<ValueState>* N) { |
| 101 | |
| 102 | ExecutionContinues(os, SMgr, GetStmt(N->getLocation())); |
| 103 | } |
| 104 | |
| 105 | static inline void ExecutionContinues(std::ostringstream& os, |
| 106 | SourceManager& SMgr, |
| 107 | const CFGBlock* B) { |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 108 | |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 109 | ExecutionContinues(os, SMgr, GetStmt(B)); |
| 110 | } |
| 111 | |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 112 | |
| 113 | Stmt* BugReport::getStmt(BugReporter& BR) const { |
| 114 | |
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 | |
| 118 | if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) |
| 119 | if (BE->getBlock() == &BR.getCFG().getExit()) |
Ted Kremenek | 200ed92 | 2008-05-02 23:21:21 +0000 | [diff] [blame] | 120 | S = GetLastStmt(EndNode); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 121 | if (!S) |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 122 | S = GetStmt(ProgP); |
| 123 | |
| 124 | return S; |
| 125 | } |
| 126 | |
| 127 | PathDiagnosticPiece* |
| 128 | BugReport::getEndPath(BugReporter& BR, |
| 129 | ExplodedNode<ValueState>* EndPathNode) { |
| 130 | |
| 131 | Stmt* S = getStmt(BR); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 132 | |
| 133 | if (!S) |
| 134 | return NULL; |
| 135 | |
Ted Kremenek | c9fa2f7 | 2008-05-01 23:13:35 +0000 | [diff] [blame] | 136 | FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager()); |
| 137 | PathDiagnosticPiece* P = new PathDiagnosticPiece(L, getDescription()); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 138 | |
Ted Kremenek | de7161f | 2008-04-03 18:00:37 +0000 | [diff] [blame] | 139 | const SourceRange *Beg, *End; |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 140 | getRanges(BR, Beg, End); |
| 141 | |
| 142 | for (; Beg != End; ++Beg) |
| 143 | P->addRange(*Beg); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 144 | |
| 145 | return P; |
| 146 | } |
| 147 | |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 148 | void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg, |
| 149 | const SourceRange*& end) { |
| 150 | |
| 151 | if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) { |
| 152 | R = E->getSourceRange(); |
| 153 | beg = &R; |
| 154 | end = beg+1; |
| 155 | } |
| 156 | else |
| 157 | beg = end = 0; |
Ted Kremenek | f1ae705 | 2008-04-03 17:57:38 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 160 | FullSourceLoc BugReport::getLocation(SourceManager& Mgr) { |
| 161 | |
Ted Kremenek | 200ed92 | 2008-05-02 23:21:21 +0000 | [diff] [blame] | 162 | if (!EndNode) |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 163 | return FullSourceLoc(); |
| 164 | |
Ted Kremenek | 200ed92 | 2008-05-02 23:21:21 +0000 | [diff] [blame] | 165 | Stmt* S = GetStmt(EndNode->getLocation()); |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 166 | |
| 167 | if (!S) |
| 168 | return FullSourceLoc(); |
| 169 | |
| 170 | return FullSourceLoc(S->getLocStart(), Mgr); |
| 171 | } |
| 172 | |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 173 | PathDiagnosticPiece* BugReport::VisitNode(ExplodedNode<ValueState>* N, |
| 174 | ExplodedNode<ValueState>* PrevN, |
| 175 | ExplodedGraph<ValueState>& G, |
Ted Kremenek | 8dd5646 | 2008-04-18 03:39:05 +0000 | [diff] [blame] | 176 | BugReporter& BR) { |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 177 | return NULL; |
| 178 | } |
| 179 | |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 180 | static std::pair<ExplodedGraph<ValueState>*, ExplodedNode<ValueState>*> |
| 181 | MakeReportGraph(ExplodedGraph<ValueState>* G, ExplodedNode<ValueState>* N) { |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 182 | |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 183 | llvm::OwningPtr<ExplodedGraph<ValueState> > GTrim(G->Trim(&N, &N+1)); |
| 184 | |
Ted Kremenek | 910e999 | 2008-04-25 01:25:15 +0000 | [diff] [blame] | 185 | // Find the error node in the trimmed graph. |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 186 | |
Ted Kremenek | 910e999 | 2008-04-25 01:25:15 +0000 | [diff] [blame] | 187 | ExplodedNode<ValueState>* NOld = N; |
| 188 | N = 0; |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 189 | |
Ted Kremenek | 50a6d0c | 2008-04-09 21:41:14 +0000 | [diff] [blame] | 190 | for (ExplodedGraph<ValueState>::node_iterator |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 191 | I = GTrim->nodes_begin(), E = GTrim->nodes_end(); I != E; ++I) { |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 192 | |
Ted Kremenek | 910e999 | 2008-04-25 01:25:15 +0000 | [diff] [blame] | 193 | if (I->getState() == NOld->getState() && |
| 194 | I->getLocation() == NOld->getLocation()) { |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 195 | N = &*I; |
Ted Kremenek | 94826a7 | 2008-04-03 04:59:14 +0000 | [diff] [blame] | 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 200 | assert(N); |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 201 | |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 202 | // Create a new graph with a single path. |
| 203 | |
| 204 | G = new ExplodedGraph<ValueState>(GTrim->getCFG(), GTrim->getCodeDecl(), |
| 205 | GTrim->getContext()); |
| 206 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 207 | // Sometimes TrimGraph can contain a cycle. Perform a reverse DFS |
| 208 | // to the root node, and then construct a new graph that contains only |
| 209 | // a single path. |
| 210 | llvm::DenseMap<void*,unsigned> Visited; |
| 211 | llvm::SmallVector<ExplodedNode<ValueState>*, 10> WS; |
| 212 | WS.push_back(N); |
| 213 | unsigned cnt = 0; |
| 214 | ExplodedNode<ValueState>* Root = 0; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 215 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 216 | while (!WS.empty()) { |
| 217 | ExplodedNode<ValueState>* Node = WS.back(); |
| 218 | WS.pop_back(); |
| 219 | |
| 220 | if (Visited.find(Node) != Visited.end()) |
| 221 | continue; |
| 222 | |
| 223 | Visited[Node] = cnt++; |
| 224 | |
| 225 | if (Node->pred_empty()) { |
| 226 | Root = Node; |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | for (ExplodedNode<ValueState>::pred_iterator I=Node->pred_begin(), |
| 231 | E=Node->pred_end(); I!=E; ++I) |
| 232 | WS.push_back(*I); |
| 233 | } |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 234 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 235 | assert (Root); |
| 236 | |
| 237 | // Now walk from the root down the DFS path, always taking the successor |
| 238 | // with the lowest number. |
| 239 | ExplodedNode<ValueState> *Last = 0, *First = 0; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 240 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 241 | for ( N = Root ;;) { |
| 242 | |
| 243 | // Lookup the number associated with the current node. |
| 244 | llvm::DenseMap<void*,unsigned>::iterator I=Visited.find(N); |
| 245 | assert (I != Visited.end()); |
| 246 | |
| 247 | // Create the equivalent node in the new graph with the same state |
| 248 | // and location. |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 249 | ExplodedNode<ValueState>* NewN = |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 250 | G->getNode(N->getLocation(), N->getState()); |
| 251 | |
| 252 | // Link up the new node with the previous node. |
| 253 | if (Last) |
| 254 | NewN->addPredecessor(Last); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 255 | |
| 256 | Last = NewN; |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 257 | |
| 258 | // Are we at the final node? |
| 259 | if (I->second == 0) { |
| 260 | First = NewN; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 261 | break; |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 262 | } |
| 263 | |
| 264 | // Find the next successor node. We choose the node that is marked |
| 265 | // with the lowest DFS number. |
| 266 | ExplodedNode<ValueState>::succ_iterator SI = N->succ_begin(); |
| 267 | ExplodedNode<ValueState>::succ_iterator SE = N->succ_end(); |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 268 | N = 0; |
| 269 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 270 | for (unsigned MinVal = 0; SI != SE; ++SI) { |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 271 | |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 272 | I = Visited.find(*SI); |
| 273 | |
| 274 | if (I == Visited.end()) |
| 275 | continue; |
| 276 | |
| 277 | if (!N || I->second < MinVal) { |
| 278 | N = *SI; |
| 279 | MinVal = I->second; |
Ted Kremenek | c1da441 | 2008-06-17 19:14:06 +0000 | [diff] [blame] | 280 | } |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 281 | } |
| 282 | |
| 283 | assert (N); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 284 | } |
Ted Kremenek | 331b0ac | 2008-06-18 05:34:07 +0000 | [diff] [blame^] | 285 | |
| 286 | assert (First); |
Ted Kremenek | 6aaca9c | 2008-04-23 23:04:32 +0000 | [diff] [blame] | 287 | return std::make_pair(G, First); |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 290 | static VarDecl* GetMostRecentVarDeclBinding(ExplodedNode<ValueState>* N, |
| 291 | ValueStateManager& VMgr, |
| 292 | RVal X) { |
| 293 | |
| 294 | for ( ; N ; N = N->pred_empty() ? 0 : *N->pred_begin()) { |
| 295 | |
| 296 | ProgramPoint P = N->getLocation(); |
| 297 | |
| 298 | if (!isa<PostStmt>(P)) |
| 299 | continue; |
| 300 | |
| 301 | DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt()); |
| 302 | |
| 303 | if (!DR) |
| 304 | continue; |
| 305 | |
| 306 | RVal Y = VMgr.GetRVal(N->getState(), DR); |
| 307 | |
| 308 | if (X != Y) |
| 309 | continue; |
| 310 | |
| 311 | VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()); |
| 312 | |
| 313 | if (!VD) |
| 314 | continue; |
| 315 | |
| 316 | return VD; |
| 317 | } |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | static void HandleNotableSymbol(ExplodedNode<ValueState>* N, Stmt* S, |
| 324 | SymbolID Sym, BugReporter& BR, |
| 325 | PathDiagnostic& PD) { |
| 326 | |
| 327 | ExplodedNode<ValueState>* Pred = N->pred_empty() ? 0 : *N->pred_begin(); |
| 328 | ValueState* PrevSt = Pred ? Pred->getState() : 0; |
| 329 | |
| 330 | if (!PrevSt) |
| 331 | return; |
| 332 | |
| 333 | // Look at the variable bindings of the current state that map to the |
| 334 | // specified symbol. Are any of them not in the previous state. |
| 335 | |
| 336 | ValueState* St = N->getState(); |
| 337 | ValueStateManager& VMgr = BR.getStateManager(); |
| 338 | |
| 339 | // FIXME: Later generalize for a broader memory model. |
| 340 | |
| 341 | // FIXME: This is quadratic, since its nested in another loop. Probably |
| 342 | // doesn't matter, but keep an eye out for performance issues. It's |
| 343 | // also a bunch of copy-paste. Bad. Cleanup later. |
| 344 | |
| 345 | for (ValueState::vb_iterator I=St->vb_begin(), E=St->vb_end(); I!=E; ++I){ |
| 346 | |
| 347 | RVal V = I.getData(); |
| 348 | SymbolID ScanSym; |
| 349 | |
| 350 | if (lval::SymbolVal* SV = dyn_cast<lval::SymbolVal>(&V)) |
| 351 | ScanSym = SV->getSymbol(); |
| 352 | else if (nonlval::SymbolVal* SV = dyn_cast<nonlval::SymbolVal>(&V)) |
| 353 | ScanSym = SV->getSymbol(); |
| 354 | else |
| 355 | continue; |
| 356 | |
| 357 | if (ScanSym != Sym) |
| 358 | continue; |
| 359 | |
| 360 | // Check if the previous state has this binding. |
| 361 | |
| 362 | RVal X = VMgr.GetRVal(PrevSt, lval::DeclVal(I.getKey())); |
| 363 | |
| 364 | if (X == V) // Same binding? |
| 365 | continue; |
| 366 | |
| 367 | // Different binding. Only handle assignments for now. We don't pull |
| 368 | // this check out of the loop because we will eventually handle other |
| 369 | // cases. |
| 370 | |
| 371 | VarDecl *VD = 0; |
| 372 | |
| 373 | if (BinaryOperator* B = dyn_cast<BinaryOperator>(S)) { |
| 374 | if (!B->isAssignmentOp()) |
| 375 | continue; |
| 376 | |
| 377 | // What variable did we assign to? |
| 378 | DeclRefExpr* DR = dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParenCasts()); |
| 379 | |
| 380 | if (!DR) |
| 381 | continue; |
| 382 | |
| 383 | VD = dyn_cast<VarDecl>(DR->getDecl()); |
| 384 | } |
| 385 | else if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) |
| 386 | VD = dyn_cast<VarDecl>(DS->getDecl()); |
| 387 | |
| 388 | if (!VD) |
| 389 | continue; |
| 390 | |
| 391 | // What is the most recently referenced variable with this binding? |
| 392 | VarDecl* MostRecent = GetMostRecentVarDeclBinding(Pred, VMgr, V); |
| 393 | |
| 394 | if (!MostRecent) |
| 395 | continue; |
| 396 | |
| 397 | // Create the diagnostic. |
| 398 | |
| 399 | FullSourceLoc L(S->getLocStart(), BR.getSourceManager()); |
| 400 | |
| 401 | if (VD->getType()->isPointerLikeType()) { |
| 402 | std::string msg = "'" + std::string(VD->getName()) + |
| 403 | "' now aliases '" + MostRecent->getName() + "'"; |
| 404 | |
| 405 | PD.push_front(new PathDiagnosticPiece(L, msg)); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
Ted Kremenek | a43a1eb | 2008-04-23 23:02:12 +0000 | [diff] [blame] | 410 | void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, |
| 411 | BugReport& R) { |
| 412 | |
| 413 | ExplodedNode<ValueState>* N = R.getEndNode(); |
| 414 | |
| 415 | if (!N) return; |
| 416 | |
| 417 | // Construct a new graph that contains only a single path from the error |
| 418 | // node to a root. |
| 419 | |
| 420 | const std::pair<ExplodedGraph<ValueState>*,ExplodedNode<ValueState>*> |
| 421 | GPair = MakeReportGraph(&getGraph(), N); |
| 422 | |
| 423 | llvm::OwningPtr<ExplodedGraph<ValueState> > ReportGraph(GPair.first); |
| 424 | assert(GPair.second->getLocation() == N->getLocation()); |
| 425 | N = GPair.second; |
| 426 | |
| 427 | // Start building the path diagnostic... |
| 428 | |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 429 | if (PathDiagnosticPiece* Piece = R.getEndPath(*this, N)) |
| 430 | PD.push_back(Piece); |
| 431 | else |
| 432 | return; |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 433 | |
| 434 | ExplodedNode<ValueState>* NextNode = N->pred_empty() |
| 435 | ? NULL : *(N->pred_begin()); |
| 436 | |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 437 | SourceManager& SMgr = Ctx.getSourceManager(); |
| 438 | |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 439 | while (NextNode) { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 440 | |
| 441 | ExplodedNode<ValueState>* LastNode = N; |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 442 | N = NextNode; |
Ted Kremenek | bd7efa8 | 2008-04-17 23:44:37 +0000 | [diff] [blame] | 443 | NextNode = GetNextNode(N); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 444 | |
| 445 | ProgramPoint P = N->getLocation(); |
| 446 | |
| 447 | if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) { |
| 448 | |
| 449 | CFGBlock* Src = BE->getSrc(); |
| 450 | CFGBlock* Dst = BE->getDst(); |
| 451 | |
| 452 | Stmt* T = Src->getTerminator(); |
| 453 | |
| 454 | if (!T) |
| 455 | continue; |
| 456 | |
| 457 | FullSourceLoc L(T->getLocStart(), SMgr); |
| 458 | |
| 459 | switch (T->getStmtClass()) { |
| 460 | default: |
| 461 | break; |
| 462 | |
| 463 | case Stmt::GotoStmtClass: |
| 464 | case Stmt::IndirectGotoStmtClass: { |
| 465 | |
| 466 | Stmt* S = GetStmt(LastNode->getLocation()); |
| 467 | |
| 468 | if (!S) |
| 469 | continue; |
| 470 | |
| 471 | std::ostringstream os; |
| 472 | |
| 473 | os << "Control jumps to line " |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 474 | << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 475 | |
| 476 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 477 | break; |
| 478 | } |
| 479 | |
| 480 | case Stmt::SwitchStmtClass: { |
| 481 | |
| 482 | // Figure out what case arm we took. |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 483 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 484 | std::ostringstream os; |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 485 | |
| 486 | if (Stmt* S = Dst->getLabel()) |
| 487 | switch (S->getStmtClass()) { |
| 488 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 489 | default: |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 490 | assert(false && "Not a valid switch label."); |
| 491 | continue; |
| 492 | |
Ted Kremenek | 8b90455 | 2008-04-22 22:29:46 +0000 | [diff] [blame] | 493 | case Stmt::DefaultStmtClass: { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 494 | |
| 495 | os << "Control jumps to the 'default' case at line " |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 496 | << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 497 | |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | case Stmt::CaseStmtClass: { |
| 502 | |
| 503 | os << "Control jumps to 'case "; |
| 504 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 505 | CaseStmt* Case = cast<CaseStmt>(S); |
| 506 | Expr* LHS = Case->getLHS()->IgnoreParenCasts(); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 507 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 508 | // Determine if it is an enum. |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 509 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 510 | bool GetRawInt = true; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 511 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 512 | if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS)) { |
| 513 | |
| 514 | // FIXME: Maybe this should be an assertion. Are there cases |
| 515 | // were it is not an EnumConstantDecl? |
| 516 | |
| 517 | EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(DR->getDecl()); |
| 518 | |
| 519 | if (D) { |
| 520 | GetRawInt = false; |
| 521 | os << D->getName(); |
| 522 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 523 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 524 | |
| 525 | if (GetRawInt) { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 526 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 527 | // Not an enum. |
| 528 | Expr* CondE = cast<SwitchStmt>(T)->getCond(); |
| 529 | unsigned bits = Ctx.getTypeSize(CondE->getType()); |
| 530 | llvm::APSInt V(bits, false); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 531 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 532 | if (!LHS->isIntegerConstantExpr(V, Ctx, 0, true)) { |
| 533 | assert (false && "Case condition must be constant."); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 534 | continue; |
| 535 | } |
| 536 | |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 537 | os << V.toString(); |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 538 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 539 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 540 | os << ":' at line " |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 541 | << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n"; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 542 | |
| 543 | break; |
| 544 | |
| 545 | } |
| 546 | } |
Ted Kremenek | 5678392 | 2008-04-25 01:29:56 +0000 | [diff] [blame] | 547 | else { |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 548 | os << "'Default' branch taken."; |
| 549 | ExecutionContinues(os, SMgr, LastNode); |
Ted Kremenek | 5678392 | 2008-04-25 01:29:56 +0000 | [diff] [blame] | 550 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 551 | |
| 552 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 553 | break; |
| 554 | } |
Ted Kremenek | 2673c9f | 2008-04-25 19:01:27 +0000 | [diff] [blame] | 555 | |
| 556 | case Stmt::BreakStmtClass: |
| 557 | case Stmt::ContinueStmtClass: { |
| 558 | std::ostringstream os; |
| 559 | ExecutionContinues(os, SMgr, LastNode); |
| 560 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 561 | break; |
| 562 | } |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 563 | |
| 564 | case Stmt::ConditionalOperatorClass: { |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 565 | |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 566 | std::ostringstream os; |
| 567 | os << "'?' condition evaluates to "; |
| 568 | |
| 569 | if (*(Src->succ_begin()+1) == Dst) |
| 570 | os << "false."; |
| 571 | else |
| 572 | os << "true."; |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 573 | |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 574 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 575 | |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | case Stmt::DoStmtClass: { |
| 580 | |
| 581 | if (*(Src->succ_begin()) == Dst) { |
| 582 | |
| 583 | std::ostringstream os; |
| 584 | |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 585 | os << "Loop condition is true."; |
| 586 | ExecutionContinues(os, SMgr, Dst); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 587 | |
| 588 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 589 | } |
| 590 | else |
| 591 | PD.push_front(new PathDiagnosticPiece(L, |
| 592 | "Loop condition is false. Exiting loop.")); |
| 593 | |
| 594 | break; |
| 595 | } |
| 596 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 597 | case Stmt::WhileStmtClass: |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 598 | case Stmt::ForStmtClass: { |
| 599 | |
| 600 | if (*(Src->succ_begin()+1) == Dst) { |
| 601 | |
| 602 | std::ostringstream os; |
| 603 | |
Ted Kremenek | 143ca22 | 2008-05-06 18:11:09 +0000 | [diff] [blame] | 604 | os << "Loop condition is false."; |
| 605 | ExecutionContinues(os, SMgr, Dst); |
Ted Kremenek | 706e3cf | 2008-04-07 23:35:17 +0000 | [diff] [blame] | 606 | |
| 607 | PD.push_front(new PathDiagnosticPiece(L, os.str())); |
| 608 | } |
| 609 | else |
| 610 | PD.push_front(new PathDiagnosticPiece(L, |
| 611 | "Loop condition is true. Entering loop body.")); |
| 612 | |
| 613 | break; |
| 614 | } |
| 615 | |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 616 | case Stmt::IfStmtClass: { |
| 617 | |
| 618 | if (*(Src->succ_begin()+1) == Dst) |
| 619 | PD.push_front(new PathDiagnosticPiece(L, "Taking false branch.")); |
| 620 | else |
| 621 | PD.push_front(new PathDiagnosticPiece(L, "Taking true branch.")); |
| 622 | |
| 623 | break; |
| 624 | } |
| 625 | } |
Ted Kremenek | 6837faa | 2008-04-09 00:20:43 +0000 | [diff] [blame] | 626 | } |
Ted Kremenek | 5a42995 | 2008-04-23 23:35:07 +0000 | [diff] [blame] | 627 | |
| 628 | if (PathDiagnosticPiece* p = R.VisitNode(N, NextNode, *ReportGraph, *this)) |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 629 | PD.push_front(p); |
| 630 | |
| 631 | if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) { |
| 632 | |
| 633 | ValueState* St = N->getState(); |
| 634 | |
| 635 | // Scan the lval bindings, and see if a "notable" symbol has a new |
| 636 | // lval binding. |
| 637 | |
| 638 | // FIXME: In the future, when we generalize the memory model, we'll |
| 639 | // need a way to iterate over binded locations. |
| 640 | |
| 641 | llvm::SmallSet<SymbolID, 10> AlreadyProcessed; |
| 642 | |
| 643 | for (ValueState::vb_iterator I=St->vb_begin(), E=St->vb_end(); I!=E; ++I){ |
| 644 | |
| 645 | RVal V = I.getData(); |
| 646 | SymbolID ScanSym; |
| 647 | |
| 648 | if (lval::SymbolVal* SV = dyn_cast<lval::SymbolVal>(&V)) |
| 649 | ScanSym = SV->getSymbol(); |
| 650 | else if (nonlval::SymbolVal* SV = dyn_cast<nonlval::SymbolVal>(&V)) |
| 651 | ScanSym = SV->getSymbol(); |
| 652 | else |
| 653 | continue; |
| 654 | |
| 655 | assert (ScanSym.isInitialized()); |
| 656 | |
| 657 | if (!isNotable(ScanSym)) |
| 658 | continue; |
| 659 | |
| 660 | if (AlreadyProcessed.count(ScanSym)) |
| 661 | continue; |
| 662 | |
| 663 | AlreadyProcessed.insert(ScanSym); |
| 664 | |
| 665 | HandleNotableSymbol(N, PS->getStmt(), ScanSym, *this, PD); |
| 666 | } |
| 667 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
Ted Kremenek | 1aa44c7 | 2008-05-22 23:45:19 +0000 | [diff] [blame] | 671 | |
Ted Kremenek | 95cc1ba | 2008-04-18 20:54:29 +0000 | [diff] [blame] | 672 | bool BugTypeCacheLocation::isCached(BugReport& R) { |
| 673 | |
| 674 | ExplodedNode<ValueState>* N = R.getEndNode(); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 675 | |
Ted Kremenek | 329d2cc | 2008-04-18 02:24:50 +0000 | [diff] [blame] | 676 | if (!N) |
| 677 | return false; |
Ted Kremenek | 95cc1ba | 2008-04-18 20:54:29 +0000 | [diff] [blame] | 678 | |
| 679 | // Cache the location of the error. Don't emit the same |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 680 | // warning for the same error type that occurs at the same program |
| 681 | // location but along a different path. |
| 682 | |
Ted Kremenek | 76d90c8 | 2008-05-16 18:33:14 +0000 | [diff] [blame] | 683 | return isCached(N->getLocation()); |
| 684 | } |
| 685 | |
| 686 | bool BugTypeCacheLocation::isCached(ProgramPoint P) { |
| 687 | |
| 688 | void* p = P.getRawData(); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 689 | |
| 690 | if (CachedErrors.count(p)) |
| 691 | return true; |
| 692 | |
Ted Kremenek | 95cc1ba | 2008-04-18 20:54:29 +0000 | [diff] [blame] | 693 | CachedErrors.insert(p); |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 697 | void BugReporter::EmitWarning(BugReport& R) { |
| 698 | |
Ted Kremenek | 95cc1ba | 2008-04-18 20:54:29 +0000 | [diff] [blame] | 699 | if (R.getBugType().isCached(R)) |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 700 | return; |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 701 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 702 | llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getName())); |
| 703 | GeneratePathDiagnostic(*D.get(), R); |
Ted Kremenek | 072192b | 2008-04-30 23:47:44 +0000 | [diff] [blame] | 704 | |
| 705 | // Get the meta data. |
| 706 | |
| 707 | std::pair<const char**, const char**> Meta = R.getExtraDescriptiveText(); |
| 708 | |
| 709 | for (const char** s = Meta.first; s != Meta.second; ++s) |
| 710 | D->addMeta(*s); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 711 | |
| 712 | // Emit a full diagnostic for the path if we have a PathDiagnosticClient. |
Ted Kremenek | 70d1722 | 2008-04-03 07:33:55 +0000 | [diff] [blame] | 713 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 714 | if (PD && !D->empty()) { |
| 715 | PD->HandlePathDiagnostic(D.take()); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 716 | return; |
| 717 | } |
Ted Kremenek | d2f642b | 2008-04-14 17:39:48 +0000 | [diff] [blame] | 718 | |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 719 | // We don't have a PathDiagnosticClient, but we can still emit a single |
| 720 | // line diagnostic. Determine the location. |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 721 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 722 | FullSourceLoc L = D->empty() ? R.getLocation(Ctx.getSourceManager()) |
| 723 | : D->back()->getLocation(); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 724 | |
| 725 | |
| 726 | // Determine the range. |
Ted Kremenek | 5fcca68 | 2008-04-14 18:06:42 +0000 | [diff] [blame] | 727 | |
Ted Kremenek | 4bb6ac2 | 2008-04-10 16:12:38 +0000 | [diff] [blame] | 728 | const SourceRange *Beg, *End; |
Ted Kremenek | 5fcca68 | 2008-04-14 18:06:42 +0000 | [diff] [blame] | 729 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 730 | if (!D->empty()) { |
| 731 | Beg = D->back()->ranges_begin(); |
| 732 | End = D->back()->ranges_end(); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 733 | } |
| 734 | else |
Ted Kremenek | bb77e9b | 2008-05-01 22:50:36 +0000 | [diff] [blame] | 735 | R.getRanges(*this, Beg, End); |
Ted Kremenek | 75840e1 | 2008-04-18 01:56:37 +0000 | [diff] [blame] | 736 | |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 737 | if (PD) { |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 738 | PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription()); |
| 739 | |
| 740 | for ( ; Beg != End; ++Beg) |
| 741 | piece->addRange(*Beg); |
| 742 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 743 | D->push_back(piece); |
| 744 | PD->HandlePathDiagnostic(D.take()); |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 745 | } |
| 746 | else { |
| 747 | std::ostringstream os; |
| 748 | os << "[CHECKER] "; |
| 749 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 750 | if (D->empty()) |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 751 | os << R.getDescription(); |
| 752 | else |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 753 | os << D->back()->getString(); |
Ted Kremenek | 2f0e89e | 2008-04-18 22:56:53 +0000 | [diff] [blame] | 754 | |
| 755 | |
| 756 | unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning, |
| 757 | os.str().c_str()); |
| 758 | |
| 759 | Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg); |
| 760 | } |
Ted Kremenek | 61f3e05 | 2008-04-03 04:42:52 +0000 | [diff] [blame] | 761 | } |