From af3e3d54e990b385e5a653d2994d7d41427a13b8 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 28 Mar 2009 03:37:59 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67901 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BugReporter.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index ac3d96191a..be66670641 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -151,9 +151,37 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) { while (isa(S)) { const Stmt *Parent = P.getParent(S); - if (!Parent || isa(Parent) || isa(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(Parent)->getCond() != S) + return PathDiagnosticLocation(S, SMgr); + break; + case Stmt::ForStmtClass: + if (cast(Parent)->getBody() == S) + return PathDiagnosticLocation(S, SMgr); + break; + case Stmt::IfStmtClass: + if (cast(Parent)->getCond() != S) + return PathDiagnosticLocation(S, SMgr); + break; + case Stmt::ObjCForCollectionStmtClass: + if (cast(Parent)->getBody() == S) + return PathDiagnosticLocation(S, SMgr); + break; + case Stmt::WhileStmtClass: + if (cast(Parent)->getCond() != S) + return PathDiagnosticLocation(S, SMgr); + break; + default: + break; + } + S = Parent; } -- 2.40.0