diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-04 16:10:00 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-04 16:10:00 +0000 |
commit | 64176c2c9751997bfbc0e3a7c070f5aaa767be25 (patch) | |
tree | 09811544eeb40bfa1b075c97f63d041ce708d5d0 /clang/lib/CodeGen/CGBlocks.cpp | |
parent | 92eb2cbbef54102a35d44fd5d827d092cabff306 (diff) | |
download | bcm5719-llvm-64176c2c9751997bfbc0e3a7c070f5aaa767be25.tar.gz bcm5719-llvm-64176c2c9751997bfbc0e3a7c070f5aaa767be25.zip |
For C++ copied in objects, use copy constructors in
setting up block's descriptor. This is on going work to
support c++ specific issues in setting up blocks
various APIs.
llvm-svn: 105469
Diffstat (limited to 'clang/lib/CodeGen/CGBlocks.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 850c77c4b7d..5a3e1002c62 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -364,11 +364,28 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { E = new (getContext()) DeclRefExpr(const_cast<ValueDecl*>(VD), VD->getType().getNonReferenceType(), SourceLocation()); - if (VD->getType()->isReferenceType()) - E = new (getContext()) - UnaryOperator(const_cast<Expr*>(E), UnaryOperator::AddrOf, - getContext().getPointerType(E->getType()), - SourceLocation()); + if (getContext().getLangOptions().CPlusPlus) { + if (VD->getType()->isReferenceType()) { + E = new (getContext()) + UnaryOperator(const_cast<Expr*>(E), UnaryOperator::AddrOf, + getContext().getPointerType(E->getType()), + SourceLocation()); + } + else { + QualType T = E->getType(); + if (const RecordType *RT = T->getAs<RecordType>()) { + CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl()); + if (!Record->hasTrivialCopyConstructor()) { + CXXConstructorDecl *D = Record->getCopyConstructor(getContext(), + 0); + Expr *Arg = const_cast<Expr*>(E); + E = CXXConstructExpr::Create(getContext(), T, D->getLocation(), + D, false, &Arg, 1, false, + CXXConstructExpr::CK_Complete); + } + } + } + } } } @@ -607,6 +624,10 @@ void CodeGenFunction::AllocateBlockDecl(const BlockDeclRefExpr *E) { llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const ValueDecl *VD, bool IsByRef) { + llvm::Value *&VE = BlockDeclsValue[VD]; + if (VE) + return VE; + CharUnits offset = BlockDecls[VD]; assert(!offset.isZero() && "getting address of unallocated decl"); @@ -634,12 +655,12 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const ValueDecl *VD, V = Builder.CreateLoad(V); } else { const llvm::Type *Ty = CGM.getTypes().ConvertType(VD->getType()); - Ty = llvm::PointerType::get(Ty, 0); V = Builder.CreateBitCast(V, Ty); if (VD->getType()->isReferenceType()) - V = Builder.CreateLoad(V, "tmp"); + V = Builder.CreateLoad(V, "ref.tmp"); } + VE = V; return V; } |