r263087 - Fix false positives for for-loop-analysis warning

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


Author: steven_wu
Date: Wed Mar  9 20:02:48 2016
New Revision: 263087

URL: http://llvm.org/viewvc/llvm-project?rev=263087&view=rev
Log:
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

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

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=263087&r1=263086&r2=263087&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Mar  9 20:02:48 2016
@@ -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

Added: cfe/trunk/test/SemaObjC/warn-loop-analysis.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-loop-analysis.m?rev=263087&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-loop-analysis.m (added)
+++ cfe/trunk/test/SemaObjC/warn-loop-analysis.m Wed Mar  9 20:02:48 2016
@@ -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];
+}




More information about the cfe-commits mailing list