]> granicus.if.org Git - clang/commitdiff
BugReporter, extensive path-diagnostics: add an extra control-flow edge to the
authorTed Kremenek <kremenek@apple.com>
Wed, 1 Apr 2009 21:12:06 +0000 (21:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 1 Apr 2009 21:12:06 +0000 (21:12 +0000)
enclosing statement when jumping to a subexpression.

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

lib/Analysis/BugReporter.cpp

index 434b2d5cde769376d4008e919d4df1b3507a4a93..5047e718049aa02fa058a0ee553a4d11d8a1f73f 100644 (file)
@@ -793,6 +793,38 @@ static void GenExtAddEdge(PathDiagnostic& PD,
           return;
       }
   
+  // Add an extra edge when jumping between contexts.
+  while (1) {
+    if (const Stmt *PS = PrevLoc.asStmt())    
+      if (const Stmt *NS = NewLoc.asStmt()) {
+        PathDiagnosticLocation X = PDB.getEnclosingStmtLocation(PS);
+        // FIXME: We need a version of getParent that ignores '()' and casts.
+        const Stmt *parentX = PDB.getParent(X.asStmt());
+
+        const PathDiagnosticLocation &Y = PDB.getEnclosingStmtLocation(NS);
+        // FIXME: We need a version of getParent that ignores '()' and casts.
+        const Stmt *parentY = PDB.getParent(Y.asStmt());
+
+        if (IsControlFlowExpr(parentX)) {
+          if (IsControlFlowExpr(parentY) && parentX == parentY) {
+            break;
+          }
+          else {
+            const PathDiagnosticLocation &W =
+              PDB.getEnclosingStmtLocation(PDB.getParent(parentX));
+            
+            if (W != Y) X = W;
+          }
+        }
+        
+        if (X != Y && PrevLoc.asLocation() != X.asLocation()) {
+          PD.push_front(new PathDiagnosticControlFlowPiece(X, PrevLoc));
+          PrevLoc = X;
+        }
+      }
+    break;
+  }
+  
   PD.push_front(new PathDiagnosticControlFlowPiece(NewLoc, PrevLoc));
   PrevLoc = NewLoc;
 }