summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-02-26 19:55:31 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-02-26 19:55:31 +0000
commitce2ea59d2c4f0a75dfc75a8a5241df1727601321 (patch)
tree40af1e13f9a27da87a9d1c83b33ca56bf9563569
parent9c56ec86b2566836514a99ba5d778733ec394e6a (diff)
downloadbcm5719-llvm-ce2ea59d2c4f0a75dfc75a8a5241df1727601321.tar.gz
bcm5719-llvm-ce2ea59d2c4f0a75dfc75a8a5241df1727601321.zip
Fix rewriting of byref variables in nested blocks.
Fixes radar 7692350. llvm-svn: 97254
-rw-r--r--clang/lib/Frontend/RewriteObjC.cpp11
-rw-r--r--clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm23
2 files changed, 32 insertions, 2 deletions
diff --git a/clang/lib/Frontend/RewriteObjC.cpp b/clang/lib/Frontend/RewriteObjC.cpp
index 26b32478b89..42afe173277 100644
--- a/clang/lib/Frontend/RewriteObjC.cpp
+++ b/clang/lib/Frontend/RewriteObjC.cpp
@@ -4373,7 +4373,6 @@ void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S,
// Handle specific things.
if (BlockDeclRefExpr *CDRE = dyn_cast<BlockDeclRefExpr>(S))
if (!isa<FunctionDecl>(CDRE->getDecl()) &&
- !CDRE->isByRef() &&
!isa<ParmVarDecl>(CDRE->getDecl()) &&
!InnerBlockValueDecls.count(CDRE->getDecl())) {
InnerBlockValueDecls.insert(CDRE->getDecl());
@@ -4982,7 +4981,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) {
BlockDeclRefExpr *Exp = InnerBlockDeclRefs[i];
ValueDecl *VD = Exp->getDecl();
- if (!BlockByCopyDeclsPtrSet.count(VD)) {
+ if (!Exp->isByRef() && !BlockByCopyDeclsPtrSet.count(VD)) {
// We need to save the copied-in variables in nested
// blocks because it is needed at the end for some of the API generations.
// See SynthesizeBlockLiterals routine.
@@ -4996,6 +4995,14 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
ImportedBlockDecls.insert(VD);
}
}
+ if (Exp->isByRef() && !BlockByRefDeclsPtrSet.count(VD)) {
+ InnerDeclRefs.push_back(Exp); countOfInnerDecls++;
+ BlockDeclRefs.push_back(Exp);
+ BlockByRefDeclsPtrSet.insert(VD);
+ BlockByRefDecls.push_back(VD);
+ GetBlockCallExprs(Exp);
+ ImportedBlockDecls.insert(VD);
+ }
}
InnerDeclRefsCount.push_back(countOfInnerDecls);
diff --git a/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm b/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm
new file mode 100644
index 00000000000..c6279de5e1d
--- /dev/null
+++ b/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// radar 7692350
+
+void f(void (^block)(void));
+
+@interface X {
+ int y;
+}
+- (void)foo;
+@end
+
+@implementation X
+- (void)foo {
+ __block int kerfluffle;
+ f(^{
+ f(^{
+ y = 42;
+ kerfluffle = 1;
+ });
+ });
+}
+@end
OpenPOWER on IntegriCloud