]> granicus.if.org Git - clang/commitdiff
Teach PathDiagnosticBuilder::getEnclosingStmtLocation() about while/if/do/for,
authorTed Kremenek <kremenek@apple.com>
Sat, 28 Mar 2009 03:37:59 +0000 (03:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 28 Mar 2009 03:37:59 +0000 (03:37 +0000)
etc., so that the "body" is always considered a top-level statement for edge
transitions (even if it is an expression).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67901 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BugReporter.cpp

index ac3d96191aad3572facb33da46193c303e9f2d19..be666706414a91940f4210b4ff82e69ffeeae082 100644 (file)
@@ -151,9 +151,37 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
   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;
   }