[cfe-commits] r89929 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Wed Nov 25 18:38:19 PST 2009


Author: kremenek
Date: Wed Nov 25 20:38:19 2009
New Revision: 89929

URL: http://llvm.org/viewvc/llvm-project?rev=89929&view=rev
Log:
Add a PostVisitBlockExpr() method to RetainReleaseChecker to query for
the set of variables "captured" by a block.  Until the analysis gets
more sophisticated, for now we stop the retain count tracking of any
objects (transitively) referenced by these variables.

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=89929&r1=89928&r2=89929&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Wed Nov 25 20:38:19 2009
@@ -24,6 +24,7 @@
 #include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
 #include "clang/Analysis/PathSensitive/CheckerVisitor.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/StmtVisitor.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableMap.h"
@@ -3646,10 +3647,35 @@
   CFRefCount *TF;
 public:
     RetainReleaseChecker(CFRefCount *tf) : TF(tf) {}
-    static void* getTag() { static int x = 0; return &x; }    
+    static void* getTag() { static int x = 0; return &x; }
+    
+    void PostVisitBlockExpr(CheckerContext &C, const BlockExpr *BE);
 };
 } // end anonymous namespace
 
+
+void RetainReleaseChecker::PostVisitBlockExpr(CheckerContext &C,
+                                              const BlockExpr *BE) {
+  
+  // Scan the BlockDecRefExprs for any object the retain/release checker
+  // may be tracking.  
+  if (!BE->hasBlockDeclRefExprs())
+    return;
+  
+  const GRState *state = C.getState();
+  const BlockDataRegion *R =
+    cast<BlockDataRegion>(state->getSVal(BE).getAsRegion());
+  
+  BlockDataRegion::referenced_vars_iterator I = R->referenced_vars_begin(),
+                                            E = R->referenced_vars_end();
+  
+  if (I == E)
+    return;
+  
+  state = state->scanReachableSymbols<StopTrackingCallback>(I, E).getState();
+  C.addTransition(state);
+}
+
 //===----------------------------------------------------------------------===//
 // Transfer function creation for external clients.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=89929&r1=89928&r2=89929&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Wed Nov 25 20:38:19 2009
@@ -1281,7 +1281,6 @@
   ^{}();
 }
 
-#if 0
 void test_blocks_1_indirect_release(void) {
   NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
   ^{ [number release]; }();
@@ -1292,7 +1291,6 @@
   NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
   ^{ [number retain]; }();
 }
-#endif
 
 void test_blocks_1_indirect_release_via_call(void) {
   NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning





More information about the cfe-commits mailing list