]> granicus.if.org Git - clang/commitdiff
Implement IRGen for the retain-autorelease in the lambda conversion-to-block-pointer...
authorEli Friedman <eli.friedman@gmail.com>
Tue, 28 Feb 2012 01:08:45 +0000 (01:08 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 28 Feb 2012 01:08:45 +0000 (01:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151603 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CodeGenFunction.h

index 76c91a5ff373d98582af34bde15fdcb553fef624..125e431bff0a8a76a2cfcab14b2686ede28930b7 100644 (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:
index 9792017a062d09ce3e0a7826b61f9fda9026e06b..9eb58fc603c6a592e556bfe0439821bdaf6e991c 100644 (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() {}
index 71f23623115315a430d74d473cabbc3231af9f13..42c9b7dc9b2d60731307bf9f148f46f5b651ba26 100644 (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);