Implement IRGen for the retain-autorelease in the lambda conversion-to-block-pointer outside of ARC. Testcases coming up soon.

llvm-svn: 151603
This commit is contained in:
Eli Friedman 2012-02-28 01:08:45 +00:00
parent 3bc5372fae
commit ec75fec805
3 changed files with 27 additions and 2 deletions

View File

@ -1149,8 +1149,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
return CGF.EmitARCExtendBlockObject(E);
case CK_CopyAndAutoreleaseBlockObject:
CGF.ErrorUnsupported(E, "copy/autorelease block object");
return 0;
return CGF.EmitBlockCopyAndAutorelease(Visit(E), E->getType());
case CK_FloatingRealToComplex:
case CK_FloatingComplexCast:

View File

@ -2774,5 +2774,30 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction(
return HelperFn;
}
llvm::Value *
CodeGenFunction::EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty) {
// Get selectors for retain/autorelease.
IdentifierInfo *RetainID = &getContext().Idents.get("retain");
Selector RetainSelector =
getContext().Selectors.getNullarySelector(RetainID);
IdentifierInfo *AutoreleaseID = &getContext().Idents.get("autorelease");
Selector AutoreleaseSelector =
getContext().Selectors.getNullarySelector(AutoreleaseID);
// Emit calls to retain/autorelease.
CGObjCRuntime &Runtime = CGM.getObjCRuntime();
llvm::Value *Val = Block;
RValue Result;
Result = Runtime.GenerateMessageSend(*this, ReturnValueSlot(),
Ty, RetainSelector,
Val, CallArgList(), 0, 0);
Val = Result.getScalarVal();
Result = Runtime.GenerateMessageSend(*this, ReturnValueSlot(),
Ty, AutoreleaseSelector,
Val, CallArgList(), 0, 0);
Val = Result.getScalarVal();
return Val;
}
CGObjCRuntime::~CGObjCRuntime() {}

View File

@ -1345,6 +1345,7 @@ public:
const ObjCPropertyImplDecl *PID);
llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction(
const ObjCPropertyImplDecl *PID);
llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags);