[PATCH] D17627: Fix false positives for for-loop-analysis warning

Steven Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 25 17:08:29 PST 2016


steven_wu created this revision.
steven_wu added reviewers: rtrieu, thakis.
steven_wu added a subscriber: cfe-commits.

-Wfor-loop-analysis was incorrectly warning about certain cases because
the DeclMatcher is not looking pass OpaqueValueExpr.

http://reviews.llvm.org/D17627

Files:
  lib/Sema/SemaStmt.cpp
  test/SemaObjC/warn-loop-analysis.m

Index: test/SemaObjC/warn-loop-analysis.m
===================================================================
--- /dev/null
+++ test/SemaObjC/warn-loop-analysis.m
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -Wloop-analysis -verify %s
+// expected-no-diagnostics
+
+ at interface MyArray
+- (id)objectAtIndexedSubscript:(unsigned int)idx;
+ at end
+
+// Do not warn on objc classes has objectAtIndexedSubscript method.
+MyArray *test;
+void foo(void);
+void foo()
+{
+ unsigned int i;
+  for( i = 42 ; i > 0; ) // No warnings here
+       (void)test[ --i ];
+}
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1440,6 +1440,11 @@
           FoundDecl = true;
     }
 
+    void VisitOpaqueValueExpr(OpaqueValueExpr *OVE) {
+      if (Expr *E = OVE->getSourceExpr())
+        Visit(E);
+    }
+
     bool FoundDeclInUse() { return FoundDecl; }
 
   };  // end class DeclMatcher


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17627.49125.patch
Type: text/x-patch
Size: 980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160226/b93e6975/attachment.bin>


More information about the cfe-commits mailing list