diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-03-31 22:32:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-03-31 22:32:41 +0000 |
commit | bc8b44c4ee7f9c4c3ad296369e72feda61bdb580 (patch) | |
tree | a86b31b86e5943a4097b5b224e095fd0c150f1b1 | |
parent | 5b67a82a2621c148694ff0f0352aa949b363934c (diff) |
-Wuninitialized should not warn about variables captured by blocks as byref.
Note this can potentially be enhanced to detect if the __block variable
is actually written by the block, or only when the block "escapes" or
is actually used, but that requires more analysis than it is probably worth
for this simple check.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128681 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/UninitializedValues.cpp | 17 | ||||
-rw-r--r-- | test/Sema/uninit-variables.c | 9 |
2 files changed, 20 insertions, 6 deletions
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index f3cf905af2..58191ec0b0 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -440,13 +440,18 @@ void TransferFunctions::BlockStmt_VisitObjCForCollectionStmt( void TransferFunctions::VisitBlockExpr(BlockExpr *be) { if (!flagBlockUses || !handler) return; - AnalysisContext::referenced_decls_iterator i, e; - llvm::tie(i, e) = ac.getReferencedBlockVars(be->getBlockDecl()); - for ( ; i != e; ++i) { - const VarDecl *vd = *i; - if (vd->getAttr<BlocksAttr>() || !vd->hasLocalStorage() || - !isTrackedVar(vd)) + const BlockDecl *bd = be->getBlockDecl(); + for (BlockDecl::capture_const_iterator i = bd->capture_begin(), + e = bd->capture_end() ; i != e; ++i) { + const VarDecl *vd = i->getVariable(); + if (!vd->hasLocalStorage()) continue; + if (!isTrackedVar(vd)) + continue; + if (i->isByRef()) { + vals[vd] = Initialized; + continue; + } Value v = vals[vd]; if (isUninitialized(v)) handler->handleUseOfUninitVariable(be, vd, isAlwaysUninit(v)); diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 85e6394eda..17bd07f3e5 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -328,3 +328,12 @@ void test50() char c[1 ? : 2]; // no-warning } +int test51(void) +{ + __block int a; + ^(void) { + a = 42; + }(); + return a; // no-warning +} + |