[PATCH] D97824: [ObjC][ARC] Don't add operand bundle `clang.arc.attachedcall` to a call if the call already has the operand bundle

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 3 12:25:53 PST 2021


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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97824.327888.patch
Type: text/x-patch
Size: 1838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210303/e00c4f90/attachment.bin>


More information about the cfe-commits mailing list