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

Steven Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 9 18:07:37 PST 2016


This revision was automatically updated to reflect the committed changes.
steven_wu marked 2 inline comments as done.
Closed by commit rL263087: Fix false positives for for-loop-analysis warning (authored by steven_wu).

Changed prior to commit:
  http://reviews.llvm.org/D17627?vs=50212&id=50221#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17627

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

Index: cfe/trunk/test/SemaObjC/warn-loop-analysis.m
===================================================================
--- cfe/trunk/test/SemaObjC/warn-loop-analysis.m
+++ cfe/trunk/test/SemaObjC/warn-loop-analysis.m
@@ -0,0 +1,15 @@
+// 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()
+{
+  unsigned int i;
+  for (i = 42; i > 0;) // No warnings here
+    (void)test[--i];
+}
Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -1440,6 +1440,18 @@
           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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17627.50221.patch
Type: text/x-patch
Size: 1330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160310/1f4300f1/attachment-0001.bin>


More information about the cfe-commits mailing list