From: Ted Kremenek Date: Tue, 5 May 2009 23:13:38 +0000 (+0000) Subject: BugReporter (extensive diagnostics): improve location context generation for the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1baed38437e08fee7ab372ba2579ce22da354c2;p=clang BugReporter (extensive diagnostics): improve location context generation for the start of 'do' and '@synchronized' statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71038 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index 8a07cd01e1..77a83fef8c 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -823,7 +823,7 @@ public: PrevLoc = PD.begin()->getLocation(); if (const Stmt *S = PrevLoc.asStmt()) - addContext(PDB.getEnclosingStmtLocation(S).asStmt()); + addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt()); } } @@ -851,6 +851,7 @@ public: void rawAddEdge(PathDiagnosticLocation NewLoc); void addContext(const Stmt *S); + void addExtendedContext(const Stmt *S); }; } // end anonymous namespace @@ -992,6 +993,31 @@ bool EdgeBuilder::IsConsumedExpr(const PathDiagnosticLocation &L) { return false; } +void EdgeBuilder::addExtendedContext(const Stmt *S) { + if (!S) + return; + + const Stmt *Parent = PDB.getParent(S); + while (Parent) { + if (isa(Parent)) + Parent = PDB.getParent(Parent); + else + break; + } + + if (Parent) { + switch (Parent->getStmtClass()) { + case Stmt::DoStmtClass: + case Stmt::ObjCAtSynchronizedStmtClass: + addContext(Parent); + default: + break; + } + } + + addContext(S); +} + void EdgeBuilder::addContext(const Stmt *S) { if (!S) return; @@ -1073,7 +1099,7 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD, EB.addContext(S); } else - EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt()); + EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt()); } continue; @@ -1088,7 +1114,7 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD, EB.addEdge(Loc, true); PD.push_front(p); if (const Stmt *S = Loc.asStmt()) - EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt()); + EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt()); } } }