diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-12-01 22:29:46 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-12-01 22:29:46 +0000 |
commit | 1ceee5c42d5c410217f67d384eecc6ea4a2bba9b (patch) | |
tree | bc20c9496400b1e3b9e476424754d4e94e61eaf1 /lib/Sema/SemaDecl.cpp | |
parent | 28f47b92e760ccf641ac91cb0fe1c12d9ca89795 (diff) |
Sema/AST work for capturing copy init expression
to be used in copy helper synthesis of __block
variables. wip.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120617 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 786a13f1d3..7b0afe1963 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3022,6 +3022,27 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (NewVD->getLinkage() == ExternalLinkage && !DC->isRecord()) AddPushedVisibilityAttribute(NewVD); + + // For variables declared as __block which require copy construction, + // must capture copy initialization expression here. + if (getLangOptions().CPlusPlus && NewVD->hasAttr<BlocksAttr>()) { + QualType T = NewVD->getType(); + if (!T->isDependentType() && !T->isReferenceType() && + T->getAs<RecordType>() && !T->isUnionType()) { + Expr *E = new (Context) DeclRefExpr(NewVD, T, + VK_LValue, SourceLocation()); + ExprResult Res = PerformCopyInitialization( + InitializedEntity::InitializeBlock(NewVD->getLocation(), + T, false), + SourceLocation(), + Owned(E)); + if (!Res.isInvalid()) { + Res = MaybeCreateCXXExprWithTemporaries(Res.get()); + Expr *Init = Res.takeAs<Expr>(); + Context.setBlockVarCopyInits(NewVD, Init); + } + } + } MarkUnusedFileScopedDecl(NewVD); return NewVD; |