[cfe-commits] r50751 - /cfe/trunk/lib/Analysis/BugReporter.cpp

Ted Kremenek kremenek at apple.com
Tue May 6 11:11:09 PDT 2008


Author: kremenek
Date: Tue May  6 13:11:09 2008
New Revision: 50751

URL: http://llvm.org/viewvc/llvm-project?rev=50751&view=rev
Log:
More refactorings in GeneratePathDiagnostic: use ExecutionContinues to display
"Execution continues..." message, which does a better job at handling corner cases.

Modified:
    cfe/trunk/lib/Analysis/BugReporter.cpp

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=50751&r1=50750&r2=50751&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Tue May  6 13:11:09 2008
@@ -48,10 +48,8 @@
 }
 
 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<Stmt*>(B->getTerminator());
-  }
   else
     return (*B)[0];
 }
@@ -75,19 +73,35 @@
   return NULL;
 }
 
-
-static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
-                               ExplodedNode<ValueState>* 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<ValueState>* 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 @@
             
             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 @@
             
             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()));
           }





More information about the cfe-commits mailing list