]> granicus.if.org Git - clang/commitdiff
EdgeBuilder: DeclStmts and BinaryOperators are not the enclosing location context...
authorTed Kremenek <kremenek@apple.com>
Mon, 11 May 2009 22:19:32 +0000 (22:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 11 May 2009 22:19:32 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71480 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BugReporter.cpp

index 5407cea4e2ca71e9ea7a8e1a66689aa4ee43d4e0..23f334239987c0d266436031327dfcc2ae009652 100644 (file)
@@ -212,7 +212,7 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
   assert(S && "Null Stmt* passed to getEnclosingStmtLocation");
   ParentMap &P = getParentMap(); 
   SourceManager &SMgr = getSourceManager();
-    
+
   while (isa<Expr>(S) && P.isConsumedExpr(cast<Expr>(S))) {
     const Stmt *Parent = P.getParentIgnoreParens(S);
     
@@ -269,6 +269,31 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
   }
   
   assert(S && "Cannot have null Stmt for PathDiagnosticLocation");
+
+  // Special case: DeclStmts can appear in for statement declarations, in which
+  //  case the ForStmt is the context.
+  if (isa<DeclStmt>(S)) {
+    if (const Stmt *Parent = P.getParent(S)) {
+      switch (Parent->getStmtClass()) {
+        case Stmt::ForStmtClass:
+        case Stmt::ObjCForCollectionStmtClass:
+          return PathDiagnosticLocation(Parent, SMgr);
+        default:
+          break;
+      }      
+    }    
+  }
+  else if (isa<BinaryOperator>(S)) {
+    // Special case: the binary operator represents the initialization
+    // code in a for statement (this can happen when the variable being
+    // initialized is an old variable.
+    if (const ForStmt *FS =
+          dyn_cast_or_null<ForStmt>(P.getParentIgnoreParens(S))) {
+      if (FS->getInit() == S)
+        return PathDiagnosticLocation(FS, SMgr);
+    }
+  }
+
   return PathDiagnosticLocation(S, SMgr);
 }