[cfe-commits] r70285 - /cfe/trunk/lib/Analysis/BugReporter.cpp
Ted Kremenek
kremenek at apple.com
Mon Apr 27 21:23:15 PDT 2009
Author: kremenek
Date: Mon Apr 27 23:23:15 2009
New Revision: 70285
URL: http://llvm.org/viewvc/llvm-project?rev=70285&view=rev
Log:
BugReporter (extensive diagnostics): Clean up do...while control-flow edges, and
add "Looping back to the head of the loop" diagnostic for loops.
Modified:
cfe/trunk/lib/Analysis/BugReporter.cpp
Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=70285&r1=70284&r2=70285&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Mon Apr 27 23:23:15 2009
@@ -249,9 +249,7 @@
else
return PathDiagnosticLocation(S, SMgr);
case Stmt::DoStmtClass:
- if (cast<DoStmt>(Parent)->getCond() != S)
return PathDiagnosticLocation(S, SMgr);
- break;
case Stmt::ForStmtClass:
if (cast<ForStmt>(Parent)->getBody() == S)
return PathDiagnosticLocation(S, SMgr);
@@ -259,7 +257,7 @@
case Stmt::IfStmtClass:
if (cast<IfStmt>(Parent)->getCond() != S)
return PathDiagnosticLocation(S, SMgr);
- break;
+ break;
case Stmt::ObjCForCollectionStmtClass:
if (cast<ObjCForCollectionStmt>(Parent)->getBody() == S)
return PathDiagnosticLocation(S, SMgr);
@@ -772,7 +770,6 @@
const PathDiagnosticLocation &Containee);
PathDiagnosticLocation getContextLocation(const PathDiagnosticLocation &L);
- void rawAddEdge(PathDiagnosticLocation NewLoc);
void popLocation() {
PathDiagnosticLocation L = CLocs.back();
@@ -790,6 +787,8 @@
S = CE->getCond();
else if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(S))
S = BE->getLHS();
+ else if (const DoStmt *DS = dyn_cast<DoStmt>(S))
+ S = DS->getCond();
else
break;
}
@@ -841,6 +840,8 @@
addEdge(PathDiagnosticLocation(S, PDB.getSourceManager()), alwaysAdd);
}
+ void rawAddEdge(PathDiagnosticLocation NewLoc);
+
void addContext(const Stmt *S);
};
} // end anonymous namespace
@@ -1007,14 +1008,39 @@
// Block edges.
if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
const CFGBlock &Blk = *BE->getSrc();
-
- if (const Stmt *Term = Blk.getTerminator())
+ const Stmt *Term = Blk.getTerminator();
+
+ if (Term)
EB.addContext(Term);
+ // Are we jumping to the head of a loop? Add a special diagnostic.
+ if (const Stmt *Loop = BE->getDst()->getLoopTarget()) {
+
+ PathDiagnosticLocation L(Loop, PDB.getSourceManager());
+ PathDiagnosticEventPiece *p =
+ new PathDiagnosticEventPiece(L,
+ "Looping back to the head of the loop");
+
+ EB.addEdge(p->getLocation(), true);
+ PD.push_front(p);
+
+ if (!Term) {
+ const CompoundStmt *CS = NULL;
+ if (const ForStmt *FS = dyn_cast<ForStmt>(Loop))
+ CS = dyn_cast<CompoundStmt>(FS->getBody());
+ else if (const WhileStmt *WS = dyn_cast<WhileStmt>(Loop))
+ CS = dyn_cast<CompoundStmt>(WS->getBody());
+
+ if (CS)
+ EB.rawAddEdge(PathDiagnosticLocation(CS->getRBracLoc(),
+ PDB.getSourceManager()));
+ }
+ }
+
continue;
}
- if (const BlockEntrance *BE = dyn_cast<BlockEntrance>(&P)) {
+ if (const BlockEntrance *BE = dyn_cast<BlockEntrance>(&P)) {
if (const Stmt* S = BE->getFirstStmt()) {
if (IsControlFlowExpr(S))
EB.addContext(S);
More information about the cfe-commits
mailing list