[cfe-commits] r71043 - /cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp

Mike Stump mrs at apple.com
Tue May 5 17:04:14 PDT 2009


Author: mrs
Date: Tue May  5 19:04:13 2009
New Revision: 71043

URL: http://llvm.org/viewvc/llvm-project?rev=71043&view=rev
Log:
Merge in 71038:

BugReporter (extensive diagnostics): improve location context generation for the
start of 'do' and '@synchronized' statements.

Modified:
    cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp

Modified: cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp?rev=71043&r1=71042&r2=71043&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp Tue May  5 19:04:13 2009
@@ -823,7 +823,7 @@
         PrevLoc = PD.begin()->getLocation();
         
         if (const Stmt *S = PrevLoc.asStmt())
-          addContext(PDB.getEnclosingStmtLocation(S).asStmt());
+          addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
       }
   }
 
@@ -851,6 +851,7 @@
   void rawAddEdge(PathDiagnosticLocation NewLoc);
   
   void addContext(const Stmt *S);
+  void addExtendedContext(const Stmt *S);
 };  
 } // end anonymous namespace
 
@@ -992,6 +993,31 @@
   return false;
 }
   
+void EdgeBuilder::addExtendedContext(const Stmt *S) {
+  if (!S)
+    return;
+  
+  const Stmt *Parent = PDB.getParent(S);  
+  while (Parent) {
+    if (isa<CompoundStmt>(Parent))
+      Parent = PDB.getParent(Parent);
+    else
+      break;
+  }
+
+  if (Parent) {
+    switch (Parent->getStmtClass()) {
+      case Stmt::DoStmtClass:
+      case Stmt::ObjCAtSynchronizedStmtClass:
+        addContext(Parent);
+      default:
+        break;
+    }
+  }
+  
+  addContext(S);
+}
+  
 void EdgeBuilder::addContext(const Stmt *S) {
   if (!S)
     return;
@@ -1073,7 +1099,7 @@
          EB.addContext(S);
        }
        else
-         EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt());
+         EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
       }
 
       continue;
@@ -1088,7 +1114,7 @@
       EB.addEdge(Loc, true);
       PD.push_front(p);
       if (const Stmt *S = Loc.asStmt())
-        EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt());      
+        EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());      
     }
   }
 }





More information about the cfe-commits mailing list