Use the BlockDecl captures list to infer the direct captures for a BlockDataRegion...
authorTed Kremenek <kremenek@apple.com>
Thu, 6 Dec 2012 07:17:26 +0000 (07:17 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 6 Dec 2012 07:17:26 +0000 (07:17 +0000)
We still need to do a recursive walk to determine all static/global variables
referenced by a block, which is needed for region invalidation.

llvm-svn: 169481

clang/lib/Analysis/AnalysisDeclContext.cpp
clang/test/Analysis/blocks.m

index 83d441e..bcaad9b 100644 (file)
@@ -402,9 +402,6 @@ public:
       if (!VD->hasLocalStorage()) {
         if (Visited.insert(VD))
           BEVals.push_back(VD, BC);
-      } else if (DR->refersToEnclosingLocal()) {
-        if (Visited.insert(VD) && IsTrackedDecl(VD))
-          BEVals.push_back(VD, BC);
       }
     }
   }
@@ -439,7 +436,13 @@ static DeclVec* LazyInitializeReferencedDecls(const BlockDecl *BD,
   DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
   new (BV) DeclVec(BC, 10);
 
-  // Find the referenced variables.
+  // Go through the capture list.
+  for (BlockDecl::capture_const_iterator CI = BD->capture_begin(),
+       CE = BD->capture_end(); CI != CE; ++CI) {
+    BV->push_back(CI->getVariable(), BC);
+  }
+
+  // Find the referenced global/static variables.
   FindBlockDeclRefExprsVals F(*BV, BC);
   F.Visit(BD->getBody());
 
index 8aa65a3..2fa5a8e 100644 (file)
@@ -97,7 +97,6 @@ void testMessaging() {
 }
 
 
-// FALSE POSITIVE <rdar://problem/12415065>
 @interface rdar12415065 : NSObject
 @end
 
@@ -112,8 +111,9 @@ void testMessaging() {
   if (!queue)
     return;
 
-  // FALSE POSITIVE
-  // expected-warning@+1 {{Variable 'x' is uninitialized when captured by block}}
+  // This previously was a false positive with 'x' being flagged as being
+  // uninitialized when captured by the exterior block (when it is only
+  // captured by the interior block).
   dispatch_async(queue, ^{
     double x = 0.0;
     if (24.0f < x) {