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

Ted Kremenek kremenek at apple.com
Mon Apr 7 16:35:17 PDT 2008


Author: kremenek
Date: Mon Apr  7 18:35:17 2008
New Revision: 49356

URL: http://llvm.org/viewvc/llvm-project?rev=49356&view=rev
Log:
Improve BugReport diagnostics for loops and ? operator.

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=49356&r1=49355&r2=49356&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Mon Apr  7 18:35:17 2008
@@ -41,6 +41,11 @@
   return NULL;
 }
 
+static inline Stmt* GetStmt(const CFGBlock* B) {
+  assert (!B->empty());
+  return (*B)[0];
+}
+
 
 PathDiagnosticPiece*
 BugDescription::getEndPath(ASTContext& Ctx, ExplodedNode<ValueState> *N) const {
@@ -142,7 +147,7 @@
           std::ostringstream os;
           
           os << "Control jumps to line "
-          << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+             << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
           
           PD.push_front(new PathDiagnosticPiece(L, os.str()));
           break;
@@ -206,7 +211,7 @@
               }
               
               os << ":'  at line " 
-              << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+                << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
               
               break;
               
@@ -216,11 +221,59 @@
           PD.push_front(new PathDiagnosticPiece(L, os.str()));
           break;
         }
+
+        case Stmt::ConditionalOperatorClass: {
+          
+          std::ostringstream os;
+          os << "'?' condition evaluates to ";
+
+          if (*(Src->succ_begin()+1) == Dst)
+            os << "false.";
+          else
+            os << "true.";
+          
+          PD.push_front(new PathDiagnosticPiece(L, os.str()));
+          
+          break;
+        }
           
+        case Stmt::DoStmtClass:  {
+          
+          if (*(Src->succ_begin()) == Dst) {
+            
+            std::ostringstream os;          
+            
+            os << "Loop condition is true. Execution continues on line "
+               << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
+            
+            PD.push_front(new PathDiagnosticPiece(L, os.str()));
+          }
+          else
+            PD.push_front(new PathDiagnosticPiece(L,
+                              "Loop condition is false.  Exiting loop."));
+          
+          break;
+        }
           
-        case Stmt::DoStmtClass:
         case Stmt::WhileStmtClass:
-        case Stmt::ForStmtClass:
+        case Stmt::ForStmtClass: {
+          
+          if (*(Src->succ_begin()+1) == Dst) {
+            
+            std::ostringstream os;          
+
+            os << "Loop condition is false. Execution continues on line "
+               << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
+          
+            PD.push_front(new PathDiagnosticPiece(L, os.str()));
+          }
+          else
+            PD.push_front(new PathDiagnosticPiece(L,
+                            "Loop condition is true.  Entering loop body."));
+          
+          break;
+        }
+          
         case Stmt::IfStmtClass: {
           
           if (*(Src->succ_begin()+1) == Dst)





More information about the cfe-commits mailing list