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

Ted Kremenek kremenek at apple.com
Fri Apr 25 12:01:27 PDT 2008


Author: kremenek
Date: Fri Apr 25 14:01:27 2008
New Revision: 50286

URL: http://llvm.org/viewvc/llvm-project?rev=50286&view=rev
Log:
Fix bug in BugReporter where we didn't handle emitting diagnostics for
empty CFGBlocks that only contained a terminator.

Added improved diagnostics for break and continue statements and default branches in switch statements.

This fixes <rdar://problem/5889244>.

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=50286&r1=50285&r2=50286&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Apr 25 14:01:27 2008
@@ -48,8 +48,12 @@
 }
 
 static inline Stmt* GetStmt(const CFGBlock* B) {
-  assert (!B->empty());
-  return (*B)[0];
+  if (B->empty()) {
+    assert (B->getTerminator() && "Empty block should have a terminator.");
+    return const_cast<Stmt*>(B->getTerminator());
+  }
+  else
+    return (*B)[0];
 }
 
 Stmt* BugReport::getStmt() const {
@@ -60,7 +64,18 @@
 GetNextNode(ExplodedNode<ValueState>* N) {
   return N->pred_empty() ? NULL : *(N->pred_begin());
 }
+
+static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
+                               ExplodedNode<ValueState>* N) {
+  
+  Stmt* S = GetStmt(N->getLocation());
   
+  if (!S)
+    return;
+
+  os << "Execution continue on line "
+     << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
+}
   
 static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) {
   assert (isa<BlockEntrance>(N->getLocation()));
@@ -311,9 +326,7 @@
                 }
                 
                 os << V.toString();
-              }
-              
-              
+              }              
               
               os << ":'  at line " 
                  << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
@@ -323,16 +336,21 @@
             }
           }
           else {
-            
-            // FIXME: Get line number.
-            
-            os << "'Default' branch taken. "
-                  "Execution continues after switch statement.";
+            os << "'Default' branch taken.";
+            ExecutionContinues(os, SMgr, LastNode);
           }
           
           PD.push_front(new PathDiagnosticPiece(L, os.str()));
           break;
         }
+          
+        case Stmt::BreakStmtClass:
+        case Stmt::ContinueStmtClass: {
+          std::ostringstream os;
+          ExecutionContinues(os, SMgr, LastNode);
+          PD.push_front(new PathDiagnosticPiece(L, os.str()));
+          break;
+        }
 
         case Stmt::ConditionalOperatorClass: {
           





More information about the cfe-commits mailing list