blob: c907c248c04fb62bbe979ab21ed143a94e20fdf9 [file] [log] [blame]
Ted Kremenek61f3e052008-04-03 04:42:52 +00001// 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 Kremenek50a6d0c2008-04-09 21:41:14 +000016#include "clang/Analysis/PathSensitive/GRExprEngine.h"
Ted Kremenek61f3e052008-04-03 04:42:52 +000017#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"
24#include <sstream>
25
26using namespace clang;
27
28BugReporter::~BugReporter() {}
Ted Kremenek50a6d0c2008-04-09 21:41:14 +000029BugType::~BugType() {}
30BugReport::~BugReport() {}
Ted Kremenek5e55cda2008-04-11 18:40:29 +000031RangedBugReport::~RangedBugReport() {}
32
Ted Kremenek50a6d0c2008-04-09 21:41:14 +000033ExplodedGraph<ValueState>& BugReporter::getGraph() { return Eng.getGraph(); }
Ted Kremenek61f3e052008-04-03 04:42:52 +000034
35static inline Stmt* GetStmt(const ProgramPoint& P) {
36 if (const PostStmt* PS = dyn_cast<PostStmt>(&P)) {
37 return PS->getStmt();
38 }
39 else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) {
40 return BE->getSrc()->getTerminator();
41 }
42 else if (const BlockEntrance* BE = dyn_cast<BlockEntrance>(&P)) {
43 return BE->getFirstStmt();
44 }
45
46 assert (false && "Unsupported ProgramPoint.");
47 return NULL;
48}
49
Ted Kremenek706e3cf2008-04-07 23:35:17 +000050static inline Stmt* GetStmt(const CFGBlock* B) {
Ted Kremenek2673c9f2008-04-25 19:01:27 +000051 if (B->empty()) {
52 assert (B->getTerminator() && "Empty block should have a terminator.");
53 return const_cast<Stmt*>(B->getTerminator());
54 }
55 else
56 return (*B)[0];
Ted Kremenek706e3cf2008-04-07 23:35:17 +000057}
58
Ted Kremenekbd7efa82008-04-17 23:44:37 +000059static inline ExplodedNode<ValueState>*
60GetNextNode(ExplodedNode<ValueState>* N) {
61 return N->pred_empty() ? NULL : *(N->pred_begin());
62}
Ted Kremenek2673c9f2008-04-25 19:01:27 +000063
Ted Kremenekbd7efa82008-04-17 23:44:37 +000064static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) {
65 assert (isa<BlockEntrance>(N->getLocation()));
66
67 for (N = GetNextNode(N); N; N = GetNextNode(N)) {
68
69 ProgramPoint P = N->getLocation();
70
71 if (PostStmt* PS = dyn_cast<PostStmt>(&P))
72 return PS->getStmt();
73 }
74
75 return NULL;
76}
77
Ted Kremenekbb77e9b2008-05-01 22:50:36 +000078
79static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
80 ExplodedNode<ValueState>* N) {
Ted Kremenekbd7efa82008-04-17 23:44:37 +000081
Ted Kremenekbb77e9b2008-05-01 22:50:36 +000082 Stmt* S = GetStmt(N->getLocation());
83
84 if (!S)
85 return;
86
87 os << "Execution continue on line "
88 << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
89}
90
91
92Stmt* BugReport::getStmt(BugReporter& BR) const {
93
Ted Kremenek200ed922008-05-02 23:21:21 +000094 ProgramPoint ProgP = EndNode->getLocation();
Ted Kremenekbd7efa82008-04-17 23:44:37 +000095 Stmt *S = NULL;
96
97 if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
98 if (BE->getBlock() == &BR.getCFG().getExit())
Ted Kremenek200ed922008-05-02 23:21:21 +000099 S = GetLastStmt(EndNode);
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000100 if (!S)
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000101 S = GetStmt(ProgP);
102
103 return S;
104}
105
106PathDiagnosticPiece*
107BugReport::getEndPath(BugReporter& BR,
108 ExplodedNode<ValueState>* EndPathNode) {
109
110 Stmt* S = getStmt(BR);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000111
112 if (!S)
113 return NULL;
114
Ted Kremenekc9fa2f72008-05-01 23:13:35 +0000115 FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager());
116 PathDiagnosticPiece* P = new PathDiagnosticPiece(L, getDescription());
Ted Kremenek61f3e052008-04-03 04:42:52 +0000117
Ted Kremenekde7161f2008-04-03 18:00:37 +0000118 const SourceRange *Beg, *End;
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000119 getRanges(BR, Beg, End);
120
121 for (; Beg != End; ++Beg)
122 P->addRange(*Beg);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000123
124 return P;
125}
126
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000127void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
128 const SourceRange*& end) {
129
130 if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
131 R = E->getSourceRange();
132 beg = &R;
133 end = beg+1;
134 }
135 else
136 beg = end = 0;
Ted Kremenekf1ae7052008-04-03 17:57:38 +0000137}
138
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000139FullSourceLoc BugReport::getLocation(SourceManager& Mgr) {
140
Ted Kremenek200ed922008-05-02 23:21:21 +0000141 if (!EndNode)
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000142 return FullSourceLoc();
143
Ted Kremenek200ed922008-05-02 23:21:21 +0000144 Stmt* S = GetStmt(EndNode->getLocation());
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000145
146 if (!S)
147 return FullSourceLoc();
148
149 return FullSourceLoc(S->getLocStart(), Mgr);
150}
151
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000152PathDiagnosticPiece* BugReport::VisitNode(ExplodedNode<ValueState>* N,
153 ExplodedNode<ValueState>* PrevN,
154 ExplodedGraph<ValueState>& G,
Ted Kremenek8dd56462008-04-18 03:39:05 +0000155 BugReporter& BR) {
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000156 return NULL;
157}
158
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000159static std::pair<ExplodedGraph<ValueState>*, ExplodedNode<ValueState>*>
160MakeReportGraph(ExplodedGraph<ValueState>* G, ExplodedNode<ValueState>* N) {
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000161
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000162 llvm::OwningPtr<ExplodedGraph<ValueState> > GTrim(G->Trim(&N, &N+1));
163
Ted Kremenek910e9992008-04-25 01:25:15 +0000164 // Find the error node in the trimmed graph.
Ted Kremenek94826a72008-04-03 04:59:14 +0000165
Ted Kremenek910e9992008-04-25 01:25:15 +0000166 ExplodedNode<ValueState>* NOld = N;
167 N = 0;
Ted Kremenek94826a72008-04-03 04:59:14 +0000168
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000169 for (ExplodedGraph<ValueState>::node_iterator
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000170 I = GTrim->nodes_begin(), E = GTrim->nodes_end(); I != E; ++I) {
Ted Kremenek94826a72008-04-03 04:59:14 +0000171
Ted Kremenek910e9992008-04-25 01:25:15 +0000172 if (I->getState() == NOld->getState() &&
173 I->getLocation() == NOld->getLocation()) {
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000174 N = &*I;
Ted Kremenek94826a72008-04-03 04:59:14 +0000175 break;
176 }
177 }
178
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000179 assert(N);
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000180
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000181 // Create a new graph with a single path.
182
183 G = new ExplodedGraph<ValueState>(GTrim->getCFG(), GTrim->getCodeDecl(),
184 GTrim->getContext());
185
186
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000187 ExplodedNode<ValueState> *Last = 0, *First = 0;
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000188
189 while (N) {
190 ExplodedNode<ValueState>* NewN =
191 G->getNode(N->getLocation(), N->getState());
192
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000193 if (!First) First = NewN;
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000194 if (Last) Last->addPredecessor(NewN);
195
196 Last = NewN;
197 N = N->pred_empty() ? 0 : *(N->pred_begin());
198 }
199
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000200 return std::make_pair(G, First);
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000201}
202
203void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
204 BugReport& R) {
205
206 ExplodedNode<ValueState>* N = R.getEndNode();
207
208 if (!N) return;
209
210 // Construct a new graph that contains only a single path from the error
211 // node to a root.
212
213 const std::pair<ExplodedGraph<ValueState>*,ExplodedNode<ValueState>*>
214 GPair = MakeReportGraph(&getGraph(), N);
215
216 llvm::OwningPtr<ExplodedGraph<ValueState> > ReportGraph(GPair.first);
217 assert(GPair.second->getLocation() == N->getLocation());
218 N = GPair.second;
219
220 // Start building the path diagnostic...
221
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000222 if (PathDiagnosticPiece* Piece = R.getEndPath(*this, N))
223 PD.push_back(Piece);
224 else
225 return;
Ted Kremenek6837faa2008-04-09 00:20:43 +0000226
227 ExplodedNode<ValueState>* NextNode = N->pred_empty()
228 ? NULL : *(N->pred_begin());
229
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000230 SourceManager& SMgr = Ctx.getSourceManager();
231
Ted Kremenek6837faa2008-04-09 00:20:43 +0000232 while (NextNode) {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000233
234 ExplodedNode<ValueState>* LastNode = N;
Ted Kremenek6837faa2008-04-09 00:20:43 +0000235 N = NextNode;
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000236 NextNode = GetNextNode(N);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000237
238 ProgramPoint P = N->getLocation();
239
240 if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) {
241
242 CFGBlock* Src = BE->getSrc();
243 CFGBlock* Dst = BE->getDst();
244
245 Stmt* T = Src->getTerminator();
246
247 if (!T)
248 continue;
249
250 FullSourceLoc L(T->getLocStart(), SMgr);
251
252 switch (T->getStmtClass()) {
253 default:
254 break;
255
256 case Stmt::GotoStmtClass:
257 case Stmt::IndirectGotoStmtClass: {
258
259 Stmt* S = GetStmt(LastNode->getLocation());
260
261 if (!S)
262 continue;
263
264 std::ostringstream os;
265
266 os << "Control jumps to line "
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000267 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000268
269 PD.push_front(new PathDiagnosticPiece(L, os.str()));
270 break;
271 }
272
273 case Stmt::SwitchStmtClass: {
274
275 // Figure out what case arm we took.
Ted Kremenek5a429952008-04-23 23:35:07 +0000276
Ted Kremenek61f3e052008-04-03 04:42:52 +0000277 std::ostringstream os;
Ted Kremenek5a429952008-04-23 23:35:07 +0000278
279 if (Stmt* S = Dst->getLabel())
280 switch (S->getStmtClass()) {
281
Ted Kremenek61f3e052008-04-03 04:42:52 +0000282 default:
Ted Kremenek5a429952008-04-23 23:35:07 +0000283 assert(false && "Not a valid switch label.");
284 continue;
285
Ted Kremenek8b904552008-04-22 22:29:46 +0000286 case Stmt::DefaultStmtClass: {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000287
288 os << "Control jumps to the 'default' case at line "
Ted Kremenek6837faa2008-04-09 00:20:43 +0000289 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000290
291 break;
292 }
293
294 case Stmt::CaseStmtClass: {
295
296 os << "Control jumps to 'case ";
297
Ted Kremenek5a429952008-04-23 23:35:07 +0000298 CaseStmt* Case = cast<CaseStmt>(S);
299 Expr* LHS = Case->getLHS()->IgnoreParenCasts();
Ted Kremenek61f3e052008-04-03 04:42:52 +0000300
Ted Kremenek5a429952008-04-23 23:35:07 +0000301 // Determine if it is an enum.
Ted Kremenek61f3e052008-04-03 04:42:52 +0000302
Ted Kremenek5a429952008-04-23 23:35:07 +0000303 bool GetRawInt = true;
Ted Kremenek61f3e052008-04-03 04:42:52 +0000304
Ted Kremenek5a429952008-04-23 23:35:07 +0000305 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS)) {
306
307 // FIXME: Maybe this should be an assertion. Are there cases
308 // were it is not an EnumConstantDecl?
309
310 EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(DR->getDecl());
311
312 if (D) {
313 GetRawInt = false;
314 os << D->getName();
315 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000316 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000317
318 if (GetRawInt) {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000319
Ted Kremenek5a429952008-04-23 23:35:07 +0000320 // Not an enum.
321 Expr* CondE = cast<SwitchStmt>(T)->getCond();
322 unsigned bits = Ctx.getTypeSize(CondE->getType());
323 llvm::APSInt V(bits, false);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000324
Ted Kremenek5a429952008-04-23 23:35:07 +0000325 if (!LHS->isIntegerConstantExpr(V, Ctx, 0, true)) {
326 assert (false && "Case condition must be constant.");
Ted Kremenek61f3e052008-04-03 04:42:52 +0000327 continue;
328 }
329
Ted Kremenek5a429952008-04-23 23:35:07 +0000330 os << V.toString();
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000331 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000332
Ted Kremenek61f3e052008-04-03 04:42:52 +0000333 os << ":' at line "
Ted Kremenek5a429952008-04-23 23:35:07 +0000334 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000335
336 break;
337
338 }
339 }
Ted Kremenek56783922008-04-25 01:29:56 +0000340 else {
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000341 os << "'Default' branch taken.";
342 ExecutionContinues(os, SMgr, LastNode);
Ted Kremenek56783922008-04-25 01:29:56 +0000343 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000344
345 PD.push_front(new PathDiagnosticPiece(L, os.str()));
346 break;
347 }
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000348
349 case Stmt::BreakStmtClass:
350 case Stmt::ContinueStmtClass: {
351 std::ostringstream os;
352 ExecutionContinues(os, SMgr, LastNode);
353 PD.push_front(new PathDiagnosticPiece(L, os.str()));
354 break;
355 }
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000356
357 case Stmt::ConditionalOperatorClass: {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000358
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000359 std::ostringstream os;
360 os << "'?' condition evaluates to ";
361
362 if (*(Src->succ_begin()+1) == Dst)
363 os << "false.";
364 else
365 os << "true.";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000366
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000367 PD.push_front(new PathDiagnosticPiece(L, os.str()));
368
369 break;
370 }
371
372 case Stmt::DoStmtClass: {
373
374 if (*(Src->succ_begin()) == Dst) {
375
376 std::ostringstream os;
377
378 os << "Loop condition is true. Execution continues on line "
379 << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
380
381 PD.push_front(new PathDiagnosticPiece(L, os.str()));
382 }
383 else
384 PD.push_front(new PathDiagnosticPiece(L,
385 "Loop condition is false. Exiting loop."));
386
387 break;
388 }
389
Ted Kremenek61f3e052008-04-03 04:42:52 +0000390 case Stmt::WhileStmtClass:
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000391 case Stmt::ForStmtClass: {
392
393 if (*(Src->succ_begin()+1) == Dst) {
394
395 std::ostringstream os;
396
397 os << "Loop condition is false. Execution continues on line "
398 << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
399
400 PD.push_front(new PathDiagnosticPiece(L, os.str()));
401 }
402 else
403 PD.push_front(new PathDiagnosticPiece(L,
404 "Loop condition is true. Entering loop body."));
405
406 break;
407 }
408
Ted Kremenek61f3e052008-04-03 04:42:52 +0000409 case Stmt::IfStmtClass: {
410
411 if (*(Src->succ_begin()+1) == Dst)
412 PD.push_front(new PathDiagnosticPiece(L, "Taking false branch."));
413 else
414 PD.push_front(new PathDiagnosticPiece(L, "Taking true branch."));
415
416 break;
417 }
418 }
Ted Kremenek6837faa2008-04-09 00:20:43 +0000419 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000420
421 if (PathDiagnosticPiece* p = R.VisitNode(N, NextNode, *ReportGraph, *this))
422 PD.push_front(p);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000423 }
424}
425
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000426bool BugTypeCacheLocation::isCached(BugReport& R) {
427
428 ExplodedNode<ValueState>* N = R.getEndNode();
Ted Kremenek61f3e052008-04-03 04:42:52 +0000429
Ted Kremenek329d2cc2008-04-18 02:24:50 +0000430 if (!N)
431 return false;
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000432
433 // Cache the location of the error. Don't emit the same
Ted Kremenek61f3e052008-04-03 04:42:52 +0000434 // warning for the same error type that occurs at the same program
435 // location but along a different path.
436
437 void* p = N->getLocation().getRawData();
438
439 if (CachedErrors.count(p))
440 return true;
441
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000442 CachedErrors.insert(p);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000443 return false;
444}
445
Ted Kremenek75840e12008-04-18 01:56:37 +0000446void BugReporter::EmitWarning(BugReport& R) {
447
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000448 if (R.getBugType().isCached(R))
Ted Kremenek61f3e052008-04-03 04:42:52 +0000449 return;
Ted Kremenek75840e12008-04-18 01:56:37 +0000450
Ted Kremenek55851142008-04-22 16:15:03 +0000451 llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getName()));
452 GeneratePathDiagnostic(*D.get(), R);
Ted Kremenek072192b2008-04-30 23:47:44 +0000453
454 // Get the meta data.
455
456 std::pair<const char**, const char**> Meta = R.getExtraDescriptiveText();
457
458 for (const char** s = Meta.first; s != Meta.second; ++s)
459 D->addMeta(*s);
Ted Kremenek75840e12008-04-18 01:56:37 +0000460
461 // Emit a full diagnostic for the path if we have a PathDiagnosticClient.
Ted Kremenek70d17222008-04-03 07:33:55 +0000462
Ted Kremenek55851142008-04-22 16:15:03 +0000463 if (PD && !D->empty()) {
464 PD->HandlePathDiagnostic(D.take());
Ted Kremenek75840e12008-04-18 01:56:37 +0000465 return;
466 }
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000467
Ted Kremenek75840e12008-04-18 01:56:37 +0000468 // We don't have a PathDiagnosticClient, but we can still emit a single
469 // line diagnostic. Determine the location.
Ted Kremenek61f3e052008-04-03 04:42:52 +0000470
Ted Kremenek55851142008-04-22 16:15:03 +0000471 FullSourceLoc L = D->empty() ? R.getLocation(Ctx.getSourceManager())
472 : D->back()->getLocation();
Ted Kremenek75840e12008-04-18 01:56:37 +0000473
474
475 // Determine the range.
Ted Kremenek5fcca682008-04-14 18:06:42 +0000476
Ted Kremenek4bb6ac22008-04-10 16:12:38 +0000477 const SourceRange *Beg, *End;
Ted Kremenek5fcca682008-04-14 18:06:42 +0000478
Ted Kremenek55851142008-04-22 16:15:03 +0000479 if (!D->empty()) {
480 Beg = D->back()->ranges_begin();
481 End = D->back()->ranges_end();
Ted Kremenek75840e12008-04-18 01:56:37 +0000482 }
483 else
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000484 R.getRanges(*this, Beg, End);
Ted Kremenek75840e12008-04-18 01:56:37 +0000485
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000486 if (PD) {
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000487 PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());
488
489 for ( ; Beg != End; ++Beg)
490 piece->addRange(*Beg);
491
Ted Kremenek55851142008-04-22 16:15:03 +0000492 D->push_back(piece);
493 PD->HandlePathDiagnostic(D.take());
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000494 }
495 else {
496 std::ostringstream os;
497 os << "[CHECKER] ";
498
Ted Kremenek55851142008-04-22 16:15:03 +0000499 if (D->empty())
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000500 os << R.getDescription();
501 else
Ted Kremenek55851142008-04-22 16:15:03 +0000502 os << D->back()->getString();
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000503
504
505 unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
506 os.str().c_str());
507
508 Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
509 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000510}