[cfe-commits] r105469 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGBlocks.h test/CodeGenCXX/copy-in-cplus-object.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Jun 4 09:10:00 PDT 2010
Author: fjahanian
Date: Fri Jun 4 11:10:00 2010
New Revision: 105469
URL: http://llvm.org/viewvc/llvm-project?rev=105469&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBlocks.h
Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=105469&r1=105468&r2=105469&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Jun 4 11:10:00 2010
@@ -364,11 +364,28 @@
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 @@
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 @@
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;
}
Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=105469&r1=105468&r2=105469&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.h (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.h Fri Jun 4 11:10:00 2010
@@ -180,6 +180,9 @@
/// BlockDecls - Offsets for all Decls in BlockDeclRefExprs.
llvm::DenseMap<const Decl*, CharUnits> BlockDecls;
+
+ /// BlockDeclsValue - llvm::Value for all Decls in BlockDeclRefExprs.
+ llvm::DenseMap<const Decl*, llvm::Value *> BlockDeclsValue;
/// BlockCXXThisOffset - The offset of the C++ 'this' value within
/// the block structure.
Added: cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp?rev=105469&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/copy-in-cplus-object.cpp Fri Jun 4 11:10:00 2010
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+
+struct TestObject
+{
+ TestObject(const TestObject& inObj);
+ TestObject();
+ TestObject& operator=(const TestObject& inObj);
+ int version() const;
+
+};
+
+void testRoutine() {
+ TestObject one;
+ int (^V)() = ^{ return one.version(); };
+}
+
+// CHECK: call void @_ZN10TestObjectC1ERKS_
+
More information about the cfe-commits
mailing list