blob: 785e4cf4ae7ef1768e48fa1a081aa09d37dfa144 [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
94 ProgramPoint ProgP = N->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 Kremenekbb77e9b2008-05-01 22:50:36 +000099 S = GetLastStmt(N);
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 Kremenekbd7efa82008-04-17 23:44:37 +0000115 FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager());
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000116
117 PathDiagnosticPiece* P =
118 new PathDiagnosticPiece(L, getDescription());
Ted Kremenek61f3e052008-04-03 04:42:52 +0000119
Ted Kremenekde7161f2008-04-03 18:00:37 +0000120 const SourceRange *Beg, *End;
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000121 getRanges(BR, Beg, End);
122
123 for (; Beg != End; ++Beg)
124 P->addRange(*Beg);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000125
126 return P;
127}
128
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000129void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
130 const SourceRange*& end) {
131
132 if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
133 R = E->getSourceRange();
134 beg = &R;
135 end = beg+1;
136 }
137 else
138 beg = end = 0;
Ted Kremenekf1ae7052008-04-03 17:57:38 +0000139}
140
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000141FullSourceLoc BugReport::getLocation(SourceManager& Mgr) {
142
143 if (!N)
144 return FullSourceLoc();
145
146 Stmt* S = GetStmt(N->getLocation());
147
148 if (!S)
149 return FullSourceLoc();
150
151 return FullSourceLoc(S->getLocStart(), Mgr);
152}
153
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000154PathDiagnosticPiece* BugReport::VisitNode(ExplodedNode<ValueState>* N,
155 ExplodedNode<ValueState>* PrevN,
156 ExplodedGraph<ValueState>& G,
Ted Kremenek8dd56462008-04-18 03:39:05 +0000157 BugReporter& BR) {
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000158 return NULL;
159}
160
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000161static std::pair<ExplodedGraph<ValueState>*, ExplodedNode<ValueState>*>
162MakeReportGraph(ExplodedGraph<ValueState>* G, ExplodedNode<ValueState>* N) {
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000163
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000164 llvm::OwningPtr<ExplodedGraph<ValueState> > GTrim(G->Trim(&N, &N+1));
165
Ted Kremenek910e9992008-04-25 01:25:15 +0000166 // Find the error node in the trimmed graph.
Ted Kremenek94826a72008-04-03 04:59:14 +0000167
Ted Kremenek910e9992008-04-25 01:25:15 +0000168 ExplodedNode<ValueState>* NOld = N;
169 N = 0;
Ted Kremenek94826a72008-04-03 04:59:14 +0000170
Ted Kremenek50a6d0c2008-04-09 21:41:14 +0000171 for (ExplodedGraph<ValueState>::node_iterator
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000172 I = GTrim->nodes_begin(), E = GTrim->nodes_end(); I != E; ++I) {
Ted Kremenek94826a72008-04-03 04:59:14 +0000173
Ted Kremenek910e9992008-04-25 01:25:15 +0000174 if (I->getState() == NOld->getState() &&
175 I->getLocation() == NOld->getLocation()) {
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000176 N = &*I;
Ted Kremenek94826a72008-04-03 04:59:14 +0000177 break;
178 }
179 }
180
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000181 assert(N);
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000182
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000183 // Create a new graph with a single path.
184
185 G = new ExplodedGraph<ValueState>(GTrim->getCFG(), GTrim->getCodeDecl(),
186 GTrim->getContext());
187
188
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000189 ExplodedNode<ValueState> *Last = 0, *First = 0;
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000190
191 while (N) {
192 ExplodedNode<ValueState>* NewN =
193 G->getNode(N->getLocation(), N->getState());
194
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000195 if (!First) First = NewN;
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000196 if (Last) Last->addPredecessor(NewN);
197
198 Last = NewN;
199 N = N->pred_empty() ? 0 : *(N->pred_begin());
200 }
201
Ted Kremenek6aaca9c2008-04-23 23:04:32 +0000202 return std::make_pair(G, First);
Ted Kremeneka43a1eb2008-04-23 23:02:12 +0000203}
204
205void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
206 BugReport& R) {
207
208 ExplodedNode<ValueState>* N = R.getEndNode();
209
210 if (!N) return;
211
212 // Construct a new graph that contains only a single path from the error
213 // node to a root.
214
215 const std::pair<ExplodedGraph<ValueState>*,ExplodedNode<ValueState>*>
216 GPair = MakeReportGraph(&getGraph(), N);
217
218 llvm::OwningPtr<ExplodedGraph<ValueState> > ReportGraph(GPair.first);
219 assert(GPair.second->getLocation() == N->getLocation());
220 N = GPair.second;
221
222 // Start building the path diagnostic...
223
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000224 if (PathDiagnosticPiece* Piece = R.getEndPath(*this, N))
225 PD.push_back(Piece);
226 else
227 return;
Ted Kremenek6837faa2008-04-09 00:20:43 +0000228
229 ExplodedNode<ValueState>* NextNode = N->pred_empty()
230 ? NULL : *(N->pred_begin());
231
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000232 SourceManager& SMgr = Ctx.getSourceManager();
233
Ted Kremenek6837faa2008-04-09 00:20:43 +0000234 while (NextNode) {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000235
236 ExplodedNode<ValueState>* LastNode = N;
Ted Kremenek6837faa2008-04-09 00:20:43 +0000237 N = NextNode;
Ted Kremenekbd7efa82008-04-17 23:44:37 +0000238 NextNode = GetNextNode(N);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000239
240 ProgramPoint P = N->getLocation();
241
242 if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P)) {
243
244 CFGBlock* Src = BE->getSrc();
245 CFGBlock* Dst = BE->getDst();
246
247 Stmt* T = Src->getTerminator();
248
249 if (!T)
250 continue;
251
252 FullSourceLoc L(T->getLocStart(), SMgr);
253
254 switch (T->getStmtClass()) {
255 default:
256 break;
257
258 case Stmt::GotoStmtClass:
259 case Stmt::IndirectGotoStmtClass: {
260
261 Stmt* S = GetStmt(LastNode->getLocation());
262
263 if (!S)
264 continue;
265
266 std::ostringstream os;
267
268 os << "Control jumps to line "
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000269 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000270
271 PD.push_front(new PathDiagnosticPiece(L, os.str()));
272 break;
273 }
274
275 case Stmt::SwitchStmtClass: {
276
277 // Figure out what case arm we took.
Ted Kremenek5a429952008-04-23 23:35:07 +0000278
Ted Kremenek61f3e052008-04-03 04:42:52 +0000279 std::ostringstream os;
Ted Kremenek5a429952008-04-23 23:35:07 +0000280
281 if (Stmt* S = Dst->getLabel())
282 switch (S->getStmtClass()) {
283
Ted Kremenek61f3e052008-04-03 04:42:52 +0000284 default:
Ted Kremenek5a429952008-04-23 23:35:07 +0000285 assert(false && "Not a valid switch label.");
286 continue;
287
Ted Kremenek8b904552008-04-22 22:29:46 +0000288 case Stmt::DefaultStmtClass: {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000289
290 os << "Control jumps to the 'default' case at line "
Ted Kremenek6837faa2008-04-09 00:20:43 +0000291 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000292
293 break;
294 }
295
296 case Stmt::CaseStmtClass: {
297
298 os << "Control jumps to 'case ";
299
Ted Kremenek5a429952008-04-23 23:35:07 +0000300 CaseStmt* Case = cast<CaseStmt>(S);
301 Expr* LHS = Case->getLHS()->IgnoreParenCasts();
Ted Kremenek61f3e052008-04-03 04:42:52 +0000302
Ted Kremenek5a429952008-04-23 23:35:07 +0000303 // Determine if it is an enum.
Ted Kremenek61f3e052008-04-03 04:42:52 +0000304
Ted Kremenek5a429952008-04-23 23:35:07 +0000305 bool GetRawInt = true;
Ted Kremenek61f3e052008-04-03 04:42:52 +0000306
Ted Kremenek5a429952008-04-23 23:35:07 +0000307 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(LHS)) {
308
309 // FIXME: Maybe this should be an assertion. Are there cases
310 // were it is not an EnumConstantDecl?
311
312 EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(DR->getDecl());
313
314 if (D) {
315 GetRawInt = false;
316 os << D->getName();
317 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000318 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000319
320 if (GetRawInt) {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000321
Ted Kremenek5a429952008-04-23 23:35:07 +0000322 // Not an enum.
323 Expr* CondE = cast<SwitchStmt>(T)->getCond();
324 unsigned bits = Ctx.getTypeSize(CondE->getType());
325 llvm::APSInt V(bits, false);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000326
Ted Kremenek5a429952008-04-23 23:35:07 +0000327 if (!LHS->isIntegerConstantExpr(V, Ctx, 0, true)) {
328 assert (false && "Case condition must be constant.");
Ted Kremenek61f3e052008-04-03 04:42:52 +0000329 continue;
330 }
331
Ted Kremenek5a429952008-04-23 23:35:07 +0000332 os << V.toString();
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000333 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000334
Ted Kremenek61f3e052008-04-03 04:42:52 +0000335 os << ":' at line "
Ted Kremenek5a429952008-04-23 23:35:07 +0000336 << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000337
338 break;
339
340 }
341 }
Ted Kremenek56783922008-04-25 01:29:56 +0000342 else {
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000343 os << "'Default' branch taken.";
344 ExecutionContinues(os, SMgr, LastNode);
Ted Kremenek56783922008-04-25 01:29:56 +0000345 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000346
347 PD.push_front(new PathDiagnosticPiece(L, os.str()));
348 break;
349 }
Ted Kremenek2673c9f2008-04-25 19:01:27 +0000350
351 case Stmt::BreakStmtClass:
352 case Stmt::ContinueStmtClass: {
353 std::ostringstream os;
354 ExecutionContinues(os, SMgr, LastNode);
355 PD.push_front(new PathDiagnosticPiece(L, os.str()));
356 break;
357 }
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000358
359 case Stmt::ConditionalOperatorClass: {
Ted Kremenek61f3e052008-04-03 04:42:52 +0000360
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000361 std::ostringstream os;
362 os << "'?' condition evaluates to ";
363
364 if (*(Src->succ_begin()+1) == Dst)
365 os << "false.";
366 else
367 os << "true.";
Ted Kremenek61f3e052008-04-03 04:42:52 +0000368
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000369 PD.push_front(new PathDiagnosticPiece(L, os.str()));
370
371 break;
372 }
373
374 case Stmt::DoStmtClass: {
375
376 if (*(Src->succ_begin()) == Dst) {
377
378 std::ostringstream os;
379
380 os << "Loop condition is true. Execution continues on line "
381 << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
382
383 PD.push_front(new PathDiagnosticPiece(L, os.str()));
384 }
385 else
386 PD.push_front(new PathDiagnosticPiece(L,
387 "Loop condition is false. Exiting loop."));
388
389 break;
390 }
391
Ted Kremenek61f3e052008-04-03 04:42:52 +0000392 case Stmt::WhileStmtClass:
Ted Kremenek706e3cf2008-04-07 23:35:17 +0000393 case Stmt::ForStmtClass: {
394
395 if (*(Src->succ_begin()+1) == Dst) {
396
397 std::ostringstream os;
398
399 os << "Loop condition is false. Execution continues on line "
400 << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
401
402 PD.push_front(new PathDiagnosticPiece(L, os.str()));
403 }
404 else
405 PD.push_front(new PathDiagnosticPiece(L,
406 "Loop condition is true. Entering loop body."));
407
408 break;
409 }
410
Ted Kremenek61f3e052008-04-03 04:42:52 +0000411 case Stmt::IfStmtClass: {
412
413 if (*(Src->succ_begin()+1) == Dst)
414 PD.push_front(new PathDiagnosticPiece(L, "Taking false branch."));
415 else
416 PD.push_front(new PathDiagnosticPiece(L, "Taking true branch."));
417
418 break;
419 }
420 }
Ted Kremenek6837faa2008-04-09 00:20:43 +0000421 }
Ted Kremenek5a429952008-04-23 23:35:07 +0000422
423 if (PathDiagnosticPiece* p = R.VisitNode(N, NextNode, *ReportGraph, *this))
424 PD.push_front(p);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000425 }
426}
427
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000428bool BugTypeCacheLocation::isCached(BugReport& R) {
429
430 ExplodedNode<ValueState>* N = R.getEndNode();
Ted Kremenek61f3e052008-04-03 04:42:52 +0000431
Ted Kremenek329d2cc2008-04-18 02:24:50 +0000432 if (!N)
433 return false;
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000434
435 // Cache the location of the error. Don't emit the same
Ted Kremenek61f3e052008-04-03 04:42:52 +0000436 // warning for the same error type that occurs at the same program
437 // location but along a different path.
438
439 void* p = N->getLocation().getRawData();
440
441 if (CachedErrors.count(p))
442 return true;
443
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000444 CachedErrors.insert(p);
Ted Kremenek61f3e052008-04-03 04:42:52 +0000445 return false;
446}
447
Ted Kremenek75840e12008-04-18 01:56:37 +0000448void BugReporter::EmitWarning(BugReport& R) {
449
Ted Kremenek95cc1ba2008-04-18 20:54:29 +0000450 if (R.getBugType().isCached(R))
Ted Kremenek61f3e052008-04-03 04:42:52 +0000451 return;
Ted Kremenek75840e12008-04-18 01:56:37 +0000452
Ted Kremenek55851142008-04-22 16:15:03 +0000453 llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getName()));
454 GeneratePathDiagnostic(*D.get(), R);
Ted Kremenek072192b2008-04-30 23:47:44 +0000455
456 // Get the meta data.
457
458 std::pair<const char**, const char**> Meta = R.getExtraDescriptiveText();
459
460 for (const char** s = Meta.first; s != Meta.second; ++s)
461 D->addMeta(*s);
Ted Kremenek75840e12008-04-18 01:56:37 +0000462
463 // Emit a full diagnostic for the path if we have a PathDiagnosticClient.
Ted Kremenek70d17222008-04-03 07:33:55 +0000464
Ted Kremenek55851142008-04-22 16:15:03 +0000465 if (PD && !D->empty()) {
466 PD->HandlePathDiagnostic(D.take());
Ted Kremenek75840e12008-04-18 01:56:37 +0000467 return;
468 }
Ted Kremenekd2f642b2008-04-14 17:39:48 +0000469
Ted Kremenek75840e12008-04-18 01:56:37 +0000470 // We don't have a PathDiagnosticClient, but we can still emit a single
471 // line diagnostic. Determine the location.
Ted Kremenek61f3e052008-04-03 04:42:52 +0000472
Ted Kremenek55851142008-04-22 16:15:03 +0000473 FullSourceLoc L = D->empty() ? R.getLocation(Ctx.getSourceManager())
474 : D->back()->getLocation();
Ted Kremenek75840e12008-04-18 01:56:37 +0000475
476
477 // Determine the range.
Ted Kremenek5fcca682008-04-14 18:06:42 +0000478
Ted Kremenek4bb6ac22008-04-10 16:12:38 +0000479 const SourceRange *Beg, *End;
Ted Kremenek5fcca682008-04-14 18:06:42 +0000480
Ted Kremenek55851142008-04-22 16:15:03 +0000481 if (!D->empty()) {
482 Beg = D->back()->ranges_begin();
483 End = D->back()->ranges_end();
Ted Kremenek75840e12008-04-18 01:56:37 +0000484 }
485 else
Ted Kremenekbb77e9b2008-05-01 22:50:36 +0000486 R.getRanges(*this, Beg, End);
Ted Kremenek75840e12008-04-18 01:56:37 +0000487
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000488 if (PD) {
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000489 PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());
490
491 for ( ; Beg != End; ++Beg)
492 piece->addRange(*Beg);
493
Ted Kremenek55851142008-04-22 16:15:03 +0000494 D->push_back(piece);
495 PD->HandlePathDiagnostic(D.take());
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000496 }
497 else {
498 std::ostringstream os;
499 os << "[CHECKER] ";
500
Ted Kremenek55851142008-04-22 16:15:03 +0000501 if (D->empty())
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000502 os << R.getDescription();
503 else
Ted Kremenek55851142008-04-22 16:15:03 +0000504 os << D->back()->getString();
Ted Kremenek2f0e89e2008-04-18 22:56:53 +0000505
506
507 unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
508 os.str().c_str());
509
510 Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
511 }
Ted Kremenek61f3e052008-04-03 04:42:52 +0000512}