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

Ted Kremenek kremenek at apple.com
Fri Mar 27 20:38:16 PDT 2009


Author: kremenek
Date: Fri Mar 27 22:37:59 2009
New Revision: 67901

URL: http://llvm.org/viewvc/llvm-project?rev=67901&view=rev
Log:
Teach PathDiagnosticBuilder::getEnclosingStmtLocation() about while/if/do/for,
etc., so that the "body" is always considered a top-level statement for edge
transitions (even if it is an expression).

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=67901&r1=67900&r2=67901&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Mar 27 22:37:59 2009
@@ -151,9 +151,37 @@
   while (isa<Expr>(S)) {
     const Stmt *Parent = P.getParent(S);
     
-    if (!Parent || isa<CompoundStmt>(Parent) || isa<StmtExpr>(Parent))
-      return PathDiagnosticLocation(S, SMgr);
+    if (!Parent)
+      break;
     
+    switch (Parent->getStmtClass()) {
+      case Stmt::CompoundStmtClass:
+      case Stmt::StmtExprClass:
+        return PathDiagnosticLocation(S, SMgr);               
+      case Stmt::DoStmtClass:
+        if (cast<DoStmt>(Parent)->getCond() != S)
+          return PathDiagnosticLocation(S, SMgr); 
+        break;        
+      case Stmt::ForStmtClass:
+        if (cast<ForStmt>(Parent)->getBody() == S)
+          return PathDiagnosticLocation(S, SMgr); 
+        break;        
+      case Stmt::IfStmtClass:
+        if (cast<IfStmt>(Parent)->getCond() != S)
+          return PathDiagnosticLocation(S, SMgr);
+        break;        
+      case Stmt::ObjCForCollectionStmtClass:
+        if (cast<ObjCForCollectionStmt>(Parent)->getBody() == S)
+          return PathDiagnosticLocation(S, SMgr);
+        break;
+      case Stmt::WhileStmtClass:
+        if (cast<WhileStmt>(Parent)->getCond() != S)
+          return PathDiagnosticLocation(S, SMgr);
+        break;
+      default:
+        break;
+    }
+
     S = Parent;
   }
   





More information about the cfe-commits mailing list