[llvm-branch-commits] [cfe-branch] r71502 - /cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp
Mike Stump
mrs at apple.com
Mon May 11 16:22:25 PDT 2009
Author: mrs
Date: Mon May 11 18:22:25 2009
New Revision: 71502
URL: http://llvm.org/viewvc/llvm-project?rev=71502&view=rev
Log:
Merge in 71480:
EdgeBuilder: DeclStmts and BinaryOperators are not the enclosing location context when they are used as initialization code for loops.
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=71502&r1=71501&r2=71502&view=diff
==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/BugReporter.cpp Mon May 11 18:22:25 2009
@@ -212,7 +212,7 @@
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 @@
}
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);
}
More information about the llvm-branch-commits
mailing list