From 8bcc1bd3d51cd3df2e75a06eb9851ef3b31b844a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 6 May 2008 18:11:09 +0000 Subject: [PATCH] More refactorings in GeneratePathDiagnostic: use ExecutionContinues to display "Execution continues..." message, which does a better job at handling corner cases. llvm-svn: 50751 --- clang/lib/Analysis/BugReporter.cpp | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp index c907c248c04f..e2d98b0cf60e 100644 --- a/clang/lib/Analysis/BugReporter.cpp +++ b/clang/lib/Analysis/BugReporter.cpp @@ -48,10 +48,8 @@ static inline Stmt* GetStmt(const ProgramPoint& P) { } static inline Stmt* GetStmt(const CFGBlock* B) { - if (B->empty()) { - assert (B->getTerminator() && "Empty block should have a terminator."); + if (B->empty()) return const_cast(B->getTerminator()); - } else return (*B)[0]; } @@ -75,19 +73,35 @@ static Stmt* GetLastStmt(ExplodedNode* N) { return NULL; } - -static void ExecutionContinues(std::ostream& os, SourceManager& SMgr, - ExplodedNode* N) { - - Stmt* S = GetStmt(N->getLocation()); +static void ExecutionContinues(std::ostringstream& os, SourceManager& SMgr, + Stmt* S) { if (!S) return; - - os << "Execution continue on line " + + // Slow, but probably doesn't matter. + if (os.str().empty()) + os << ' '; + + os << "Execution continues on line " << SMgr.getLogicalLineNumber(S->getLocStart()) << '.'; } + + +static inline void ExecutionContinues(std::ostringstream& os, + SourceManager& SMgr, + ExplodedNode* N) { + + ExecutionContinues(os, SMgr, GetStmt(N->getLocation())); +} + +static inline void ExecutionContinues(std::ostringstream& os, + SourceManager& SMgr, + const CFGBlock* B) { + ExecutionContinues(os, SMgr, GetStmt(B)); +} + Stmt* BugReport::getStmt(BugReporter& BR) const { @@ -375,8 +389,8 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, std::ostringstream os; - os << "Loop condition is true. Execution continues on line " - << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.'; + os << "Loop condition is true."; + ExecutionContinues(os, SMgr, Dst); PD.push_front(new PathDiagnosticPiece(L, os.str())); } @@ -394,8 +408,8 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, std::ostringstream os; - os << "Loop condition is false. Execution continues on line " - << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.'; + os << "Loop condition is false."; + ExecutionContinues(os, SMgr, Dst); PD.push_front(new PathDiagnosticPiece(L, os.str())); }