Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -1440,6 +1440,18 @@ FoundDecl = true; } + void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { + // ObjCSubscriptRefExpr always converts its subexpressions behind OVE. + // Look pass OVE in case it has the only reference to Decl. + if (auto *OVE = dyn_cast(E->getKeyExpr())) { + if (Expr *Key = OVE->getSourceExpr()) + Visit(Key); + } else + Visit(E->getKeyExpr()); + + Visit(E->getBaseExpr()); + } + bool FoundDeclInUse() { return FoundDecl; } }; // end class DeclMatcher Index: test/SemaObjC/warn-loop-analysis.m =================================================================== --- /dev/null +++ test/SemaObjC/warn-loop-analysis.m @@ -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]; +}