Fix false positives for for-loop-analysis warning

Summary:
For PseudoObjectExpr, the DeclMatcher need to search only all the semantics
but also need to search pass OpaqueValueExpr for all potential uses for the
Decl.

Reviewers: thakis, rtrieu, rjmccall, doug.gregor

Subscribers: xazax.hun, rjmccall, doug.gregor, cfe-commits

Differential Revision: http://reviews.llvm.org/D17627

llvm-svn: 263087
This commit is contained in:
Steven Wu 2016-03-10 02:02:48 +00:00
parent 09b4a8daa3
commit 92910f69a0
2 changed files with 27 additions and 0 deletions

View File

@ -1440,6 +1440,18 @@ namespace {
FoundDecl = true;
}
void VisitPseudoObjectExpr(PseudoObjectExpr *POE) {
// Only need to visit the semantics for POE.
// SyntaticForm doesn't really use the Decal.
for (auto *S : POE->semantics()) {
if (auto *OVE = dyn_cast<OpaqueValueExpr>(S))
// Look past the OVE into the expression it binds.
Visit(OVE->getSourceExpr());
else
Visit(S);
}
}
bool FoundDeclInUse() { return FoundDecl; }
}; // end class DeclMatcher

View File

@ -0,0 +1,15 @@
// RUN: %clang_cc1 -fsyntax-only -Wloop-analysis -verify %s
// expected-no-diagnostics
@interface MyArray
- (id)objectAtIndexedSubscript:(unsigned int)idx;
@end
// Do not warn on objc classes has objectAtIndexedSubscript method.
MyArray *test;
void foo()
{
unsigned int i;
for (i = 42; i > 0;) // No warnings here
(void)test[--i];
}