From: Ted Kremenek Date: Tue, 5 May 2009 22:19:17 +0000 (+0000) Subject: BugReporter (extensive diagnostics): Fix getEnclosingStmtLocation to reason X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c42e07ef9a2978b9b4a1fde45905b2443ab6742c;p=clang BugReporter (extensive diagnostics): Fix getEnclosingStmtLocation to reason about Exprs that are not consumed and fix where the loop iteration diagnostic goes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71027 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index a9d6771309..8a07cd01e1 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -215,9 +215,9 @@ PathDiagnosticBuilder::ExecutionContinues(llvm::raw_string_ostream& os, PathDiagnosticLocation PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) { assert(S && "Null Stmt* passed to getEnclosingStmtLocation"); - ParentMap &P = getParentMap(); + ParentMap &P = getParentMap(); - while (isa(S) || isa(S)) { + while (isa(S) && P.isConsumedExpr(cast(S))) { const Stmt *Parent = P.getParent(S); if (!Parent) @@ -797,8 +797,6 @@ class VISIBILITY_HIDDEN EdgeBuilder { S = CE->getCond(); else if (const BinaryOperator *BE = dyn_cast(S)) S = BE->getLHS(); - else if (const DoStmt *DS = dyn_cast(S)) - S = DS->getCond(); else break; } @@ -1038,11 +1036,11 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD, const CFGBlock &Blk = *BE->getSrc(); const Stmt *Term = Blk.getTerminator(); - if (Term && !isa(Term)) + 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()) { + if (const Stmt *Loop = BE->getSrc()->getLoopTarget()) { PathDiagnosticLocation L(Loop, PDB.getSourceManager()); PathDiagnosticEventPiece *p = @@ -1086,8 +1084,11 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD, PDB.getBugReporter(), PDB.getNodeMapClosure()); if (p) { - EB.addEdge(p->getLocation(), true); + const PathDiagnosticLocation &Loc = p->getLocation(); + EB.addEdge(Loc, true); PD.push_front(p); + if (const Stmt *S = Loc.asStmt()) + EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt()); } } }