summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/BugReporter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-05-15 01:50:15 +0000
committerTed Kremenek <kremenek@apple.com>2009-05-15 01:50:15 +0000
commitcfe7d02b2ce4b6f616fc1feea96d82f8fc061d64 (patch)
treeeb71c0439a52a6b32eaf58898b9239b316d0695f /clang/lib/Analysis/BugReporter.cpp
parentdd20b98c3534abee65009c4e31fc6f559ed5f430 (diff)
downloadbcm5719-llvm-cfe7d02b2ce4b6f616fc1feea96d82f8fc061d64.tar.gz
bcm5719-llvm-cfe7d02b2ce4b6f616fc1feea96d82f8fc061d64.zip
BugReporter (extensive diagnostics): Add control-flow piece to '}' in
loop body when generating 'Looping back to the head of the loop' diagnostics. llvm-svn: 71829
Diffstat (limited to 'clang/lib/Analysis/BugReporter.cpp')
-rw-r--r--clang/lib/Analysis/BugReporter.cpp52
1 files changed, 36 insertions, 16 deletions
diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp
index 4726eacb320..4a4784afe98 100644
--- a/clang/lib/Analysis/BugReporter.cpp
+++ b/clang/lib/Analysis/BugReporter.cpp
@@ -207,13 +207,32 @@ PathDiagnosticBuilder::ExecutionContinues(llvm::raw_string_ostream& os,
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 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
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 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
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;
}
OpenPOWER on IntegriCloud