ahatanak updated this revision to Diff 327888.
ahatanak added a comment.

Emit a call to `@llvm.objc.retain` instead of a call to 
`@llvm.objc.retainAutoreleasedReturnValue`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97824/new/

https://reviews.llvm.org/D97824

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjCXX/arc-rv-attr.mm


Index: clang/test/CodeGenObjCXX/arc-rv-attr.mm
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjCXX/arc-rv-attr.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc 
-std=c++11 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK
+
+id foo(void);
+
+// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
+// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 
0) ]
+// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
+
+void test_list_init() {
+  auto t = id{foo()};
+}
Index: clang/lib/CodeGen/CGObjC.cpp
===================================================================
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2341,11 +2341,19 @@
   // FIXME: Do this when the target isn't aarch64.
   if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
       CGF.CGM.getTarget().getTriple().isAArch64()) {
+    auto *oldCall = cast<llvm::CallBase>(value);
+
+    // The operand bundle cannot be added if the call already has the operand
+    // bundle.
+    if (llvm::objcarc::hasAttachedCallOpBundle(oldCall))
+      // If the runtime function being called is retainRV, emit a call to
+      // @objc_retain. Do nothing if it is claimRV.
+      return IsRetainRV ? CGF.EmitARCRetainNonBlock(value) : value;
+
     llvm::Value *bundleArgs[] = {llvm::ConstantInt::get(
         CGF.Int64Ty,
         llvm::objcarc::getAttachedCallOperandBundleEnum(IsRetainRV))};
     llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
-    auto *oldCall = cast<llvm::CallBase>(value);
     llvm::CallBase *newCall = llvm::CallBase::addOperandBundle(
         oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB, oldCall);
     newCall->copyMetadata(*oldCall);


Index: clang/test/CodeGenObjCXX/arc-rv-attr.mm
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjCXX/arc-rv-attr.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -std=c++11 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK
+
+id foo(void);
+
+// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
+// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 0) ]
+// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
+
+void test_list_init() {
+  auto t = id{foo()};
+}
Index: clang/lib/CodeGen/CGObjC.cpp
===================================================================
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2341,11 +2341,19 @@
   // FIXME: Do this when the target isn't aarch64.
   if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
       CGF.CGM.getTarget().getTriple().isAArch64()) {
+    auto *oldCall = cast<llvm::CallBase>(value);
+
+    // The operand bundle cannot be added if the call already has the operand
+    // bundle.
+    if (llvm::objcarc::hasAttachedCallOpBundle(oldCall))
+      // If the runtime function being called is retainRV, emit a call to
+      // @objc_retain. Do nothing if it is claimRV.
+      return IsRetainRV ? CGF.EmitARCRetainNonBlock(value) : value;
+
     llvm::Value *bundleArgs[] = {llvm::ConstantInt::get(
         CGF.Int64Ty,
         llvm::objcarc::getAttachedCallOperandBundleEnum(IsRetainRV))};
     llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
-    auto *oldCall = cast<llvm::CallBase>(value);
     llvm::CallBase *newCall = llvm::CallBase::addOperandBundle(
         oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB, oldCall);
     newCall->copyMetadata(*oldCall);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to