Teach PathDiagnosticBuilder::getEnclosingStmtLocation() about while/if/do/for,

etc., so that the "body" is always considered a top-level statement for edge
transitions (even if it is an expression).

llvm-svn: 67901
This commit is contained in:
Ted Kremenek 2009-03-28 03:37:59 +00:00
parent a0b08dcd6b
commit b9411565ea
1 changed files with 30 additions and 2 deletions

View File

@ -151,9 +151,37 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
while (isa<Expr>(S)) {
const Stmt *Parent = P.getParent(S);
if (!Parent || isa<CompoundStmt>(Parent) || isa<StmtExpr>(Parent))
return PathDiagnosticLocation(S, SMgr);
if (!Parent)
break;
switch (Parent->getStmtClass()) {
case Stmt::CompoundStmtClass:
case Stmt::StmtExprClass:
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);
break;
case Stmt::IfStmtClass:
if (cast<IfStmt>(Parent)->getCond() != S)
return PathDiagnosticLocation(S, SMgr);
break;
case Stmt::ObjCForCollectionStmtClass:
if (cast<ObjCForCollectionStmt>(Parent)->getBody() == S)
return PathDiagnosticLocation(S, SMgr);
break;
case Stmt::WhileStmtClass:
if (cast<WhileStmt>(Parent)->getCond() != S)
return PathDiagnosticLocation(S, SMgr);
break;
default:
break;
}
S = Parent;
}