summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp43
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h10
2 files changed, 43 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 2206e8a1cd7..e21664607cf 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1006,14 +1006,36 @@ GenerateCopyHelperFunction(const llvm::StructType *T,
|| NoteForHelper[i].RequiresCopying) {
llvm::Value *Srcv = SrcObj;
Srcv = Builder.CreateStructGEP(Srcv, index);
- Srcv = Builder.CreateBitCast(Srcv,
- llvm::PointerType::get(PtrToInt8Ty, 0));
- llvm::Value *Dstv = Builder.CreateStructGEP(DstObj, index);
+ llvm::Value *Dstv;
if (NoteForHelper[i].cxxvar_import) {
- CGF.EmitSynthesizedCXXCopyCtor(Dstv, Srcv,
- NoteForHelper[i].cxxvar_import);
+ if (NoteForHelper[i].flag & BLOCK_FIELD_IS_BYREF) {
+ const ValueDecl *VD = NoteForHelper[i].cxxvar_import->getDecl();
+ const llvm::Type *PtrStructTy
+ = llvm::PointerType::get(CGF.BuildByRefType(VD), 0);
+ Srcv = Builder.CreateLoad(Srcv);
+ Srcv = Builder.CreateBitCast(Srcv, PtrStructTy);
+ Srcv = Builder.CreateStructGEP(Srcv, CGF.getByRefValueLLVMField(VD),
+ VD->getNameAsString());
+ Dstv = Builder.CreateStructGEP(DstObj, index);
+ Dstv = Builder.CreateLoad(Dstv);
+ Dstv = Builder.CreateBitCast(Dstv, PtrStructTy);
+ Dstv = Builder.CreateStructGEP(Dstv, CGF.getByRefValueLLVMField(VD),
+ VD->getNameAsString());
+ CGF.EmitSynthesizedCXXCopyCtor(Dstv, Srcv,
+ NoteForHelper[i].cxxvar_import);
+ }
+ else {
+ Srcv = Builder.CreateBitCast(Srcv,
+ llvm::PointerType::get(PtrToInt8Ty, 0));
+ Dstv = Builder.CreateStructGEP(DstObj, index);
+ CGF.EmitSynthesizedCXXCopyCtor(Dstv, Srcv,
+ NoteForHelper[i].cxxvar_import);
+ }
}
else {
+ Srcv = Builder.CreateBitCast(Srcv,
+ llvm::PointerType::get(PtrToInt8Ty, 0));
+ Dstv = Builder.CreateStructGEP(DstObj, index);
Srcv = Builder.CreateLoad(Srcv);
Dstv = Builder.CreateBitCast(Dstv, PtrToInt8Ty);
llvm::Value *N = llvm::ConstantInt::get(CGF.Int32Ty, flag);
@@ -1091,6 +1113,17 @@ GenerateDestroyHelperFunction(const llvm::StructType* T,
QualType ClassTy = E->getType();
QualType PtrClassTy = getContext().getPointerType(ClassTy);
const llvm::Type *t = CGM.getTypes().ConvertType(PtrClassTy);
+
+ if (NoteForHelper[i].flag & BLOCK_FIELD_IS_BYREF) {
+ const ValueDecl *VD = NoteForHelper[i].cxxvar_import->getDecl();
+ const llvm::Type *PtrStructTy
+ = llvm::PointerType::get(CGF.BuildByRefType(VD), 0);
+ Srcv = Builder.CreateLoad(Srcv);
+ Srcv = Builder.CreateBitCast(Srcv, PtrStructTy);
+ Srcv = Builder.CreateStructGEP(Srcv, CGF.getByRefValueLLVMField(VD),
+ VD->getNameAsString());
+
+ }
Srcv = Builder.CreateBitCast(Srcv, t);
CGF.PushDestructorCleanup(ClassTy, Srcv);
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 86a46deddd3..a3e1eac550f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -683,7 +683,11 @@ public:
/// isInConditionalBranch - Return true if we're currently emitting
/// one branch or the other of a conditional expression.
bool isInConditionalBranch() const { return ConditionalBranchLevel != 0; }
-
+
+ /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
+ /// number that holds the value.
+ unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
+
private:
CGDebugInfo *DebugInfo;
@@ -757,10 +761,6 @@ private:
llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *,
unsigned> > ByRefValueInfo;
- /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
- /// number that holds the value.
- unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
-
llvm::BasicBlock *TerminateLandingPad;
llvm::BasicBlock *TerminateHandler;
llvm::BasicBlock *TrapBB;
OpenPOWER on IntegriCloud