diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index a64b1af4f2..10c874f505 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2239,6 +2239,10 @@ llvm::Value * CGObjCMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignWeakFn, @@ -2252,6 +2256,10 @@ void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, void CGObjCMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignGlobalFn, @@ -2265,6 +2273,10 @@ void CGObjCMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, void CGObjCMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignIvarFn, @@ -2278,6 +2290,10 @@ void CGObjCMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignStrongCastFn, @@ -5096,6 +5112,10 @@ llvm::Value *CGObjCNonFragileABIMac::EmitSelector(CGBuilderTy &Builder, void CGObjCNonFragileABIMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignIvarFn, @@ -5110,6 +5130,10 @@ void CGObjCNonFragileABIMac::EmitObjCStrongCastAssign( CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignStrongCastFn, @@ -5139,6 +5163,10 @@ llvm::Value * CGObjCNonFragileABIMac::EmitObjCWeakRead( void CGObjCNonFragileABIMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignWeakFn, @@ -5152,6 +5180,10 @@ void CGObjCNonFragileABIMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dst) { + if (!isa(src->getType())) { + src = CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy); + src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); + } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); dst = CGF.Builder.CreateBitCast(dst, ObjCTypes.PtrObjectPtrTy); CGF.Builder.CreateCall2(ObjCTypes.GcAssignGlobalFn, diff --git a/test/CodeGenObjC/objc2-strong-cast.m b/test/CodeGenObjC/objc2-strong-cast.m new file mode 100644 index 0000000000..acc5d3f981 --- /dev/null +++ b/test/CodeGenObjC/objc2-strong-cast.m @@ -0,0 +1,17 @@ +// RUN: clang -fnext-runtime -emit-llvm -o %t %s + +@interface I { + __attribute__((objc_gc(strong))) signed long *_documentIDs; + __attribute__((objc_gc(strong))) id *IdocumentIDs; +} +- (void) _getResultsOfMatches; +@end + +@implementation I +-(void) _getResultsOfMatches { + _documentIDs[2] = _documentIDs[3]; + IdocumentIDs[2] = IdocumentIDs[3]; +} + +@end +