[llvm-branch-commits] [cfe-branch] r121549 - in /cfe/branches/Apple/whitney: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Sema/SemaDecl.cpp
Daniel Dunbar
daniel at zuster.org
Fri Dec 10 13:37:31 PST 2010
Author: ddunbar
Date: Fri Dec 10 15:37:30 2010
New Revision: 121549
URL: http://llvm.org/viewvc/llvm-project?rev=121549&view=rev
Log:
Merge r120617:
--
Author: Fariborz Jahanian <fjahanian at apple.com>
Date: Wed Dec 1 22:29:46 2010 +0000
Sema/AST work for capturing copy init expression
to be used in copy helper synthesis of __block
variables. wip.
*** MANUAL MERGE ***
Modified:
cfe/branches/Apple/whitney/include/clang/AST/ASTContext.h
cfe/branches/Apple/whitney/lib/AST/ASTContext.cpp
cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp
Modified: cfe/branches/Apple/whitney/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/AST/ASTContext.h?rev=121549&r1=121548&r2=121549&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/AST/ASTContext.h (original)
+++ cfe/branches/Apple/whitney/include/clang/AST/ASTContext.h Fri Dec 10 15:37:30 2010
@@ -129,6 +129,9 @@
/// \brief Mapping from ObjCContainers to their ObjCImplementations.
llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
+ /// \brief Mapping from __block VarDecls to their copy initialization expr.
+ llvm::DenseMap<VarDecl*, Expr*> BlockVarCopyInits;
+
/// \brief Representation of a "canonical" template template parameter that
/// is used in canonical template names.
class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
@@ -1356,6 +1359,12 @@
/// \brief Set the implementation of ObjCCategoryDecl.
void setObjCImplementation(ObjCCategoryDecl *CatD,
ObjCCategoryImplDecl *ImplD);
+
+ /// \brief Set the copy inialization expression of a block var decl.
+ void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
+ /// \brief Get the copy initialization expression of VarDecl,or NULL if
+ /// none exists.
+ Expr *getBlockVarCopyInits(VarDecl*VD);
/// \brief Allocate an uninitialized TypeSourceInfo.
///
Modified: cfe/branches/Apple/whitney/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/AST/ASTContext.cpp?rev=121549&r1=121548&r2=121549&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/AST/ASTContext.cpp (original)
+++ cfe/branches/Apple/whitney/lib/AST/ASTContext.cpp Fri Dec 10 15:37:30 2010
@@ -1008,6 +1008,20 @@
ObjCImpls[CatD] = ImplD;
}
+/// \brief Get the copy initialization expression of VarDecl,or NULL if
+/// none exists.
+Expr *ASTContext::getBlockVarCopyInits(VarDecl*VD) {
+ llvm::DenseMap<VarDecl*, Expr*>::iterator
+ I = BlockVarCopyInits.find(VD);
+ return (I != BlockVarCopyInits.end()) ? cast<Expr>(I->second) : 0;
+}
+
+/// \brief Set the copy inialization expression of a block var decl.
+void ASTContext::setBlockVarCopyInits(VarDecl*VD, Expr* Init) {
+ assert(VD && Init && "Passed null params");
+ BlockVarCopyInits[VD] = Init;
+}
+
/// \brief Allocate an uninitialized TypeSourceInfo.
///
/// The caller should initialize the memory held by TypeSourceInfo using
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp?rev=121549&r1=121548&r2=121549&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaDecl.cpp Fri Dec 10 15:37:30 2010
@@ -2925,6 +2925,26 @@
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, 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;
More information about the llvm-branch-commits
mailing list