Fix rewriting of byref variables in nested blocks.
Fixes radar 7692350.
llvm-svn: 97254
diff --git a/clang/lib/Frontend/RewriteObjC.cpp b/clang/lib/Frontend/RewriteObjC.cpp
index 26b3247..42afe17 100644
--- a/clang/lib/Frontend/RewriteObjC.cpp
+++ b/clang/lib/Frontend/RewriteObjC.cpp
@@ -4373,7 +4373,6 @@
// 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 @@
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 @@
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);