[llvm-branch-commits] [cfe-branch] r71830 - /cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp
Mike Stump
mrs at apple.com
Thu May 14 18:58:28 PDT 2009
Author: mrs
Date: Thu May 14 20:58:28 2009
New Revision: 71830
URL: http://llvm.org/viewvc/llvm-project?rev=71830&view=rev
Log:
Merge in 71829:
BugReporter (extensive diagnostics): Add control-flow piece to '}' in
loop body when generating 'Looping back to the head of the loop'
diagnostics.
Modified:
cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp
Modified: cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp?rev=71830&r1=71829&r2=71830&view=diff
==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp Thu May 14 20:58:28 2009
@@ -207,13 +207,32 @@
return Loc;
}
+static bool IsNested(const Stmt *S, ParentMap &PM) {
+ if (isa<Expr>(S) && PM.isConsumedExpr(cast<Expr>(S)))
+ return true;
+
+ const Stmt *Parent = PM.getParentIgnoreParens(S);
+
+ if (Parent)
+ switch (Parent->getStmtClass()) {
+ case Stmt::ForStmtClass:
+ case Stmt::DoStmtClass:
+ case Stmt::WhileStmtClass:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
PathDiagnosticLocation
PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
assert(S && "Null Stmt* passed to getEnclosingStmtLocation");
ParentMap &P = getParentMap();
SourceManager &SMgr = getSourceManager();
- while (isa<Expr>(S) && P.isConsumedExpr(cast<Expr>(S))) {
+ while (IsNested(S, P)) {
const Stmt *Parent = P.getParentIgnoreParens(S);
if (!Parent)
@@ -1106,13 +1125,18 @@
const CFGBlock &Blk = *BE->getSrc();
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->getSrc()->getLoopTarget()) {
-
+ if (const Stmt *Loop = BE->getDst()->getLoopTarget()) {
PathDiagnosticLocation L(Loop, PDB.getSourceManager());
+ const CompoundStmt *CS = NULL;
+
+ if (!Term) {
+ 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());
+ }
+
PathDiagnosticEventPiece *p =
new PathDiagnosticEventPiece(L,
"Looping back to the head of the loop");
@@ -1120,18 +1144,14 @@
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()));
+ if (CS) {
+ EB.addEdge(PathDiagnosticLocation(CS->getRBracLoc(),
+ PDB.getSourceManager()));
}
}
+
+ if (Term)
+ EB.addContext(Term);
break;
}
More information about the llvm-branch-commits
mailing list