[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
Tue Mar 2 17:50:07 PST 2021


ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a project: clang.
Herald added a subscriber: jkorous.
ahatanak requested review of this revision.

This bug was causing the call to `replaceAllUsesWith` to crash because the old call instruction and the new call instruction were the same.

rdar://74957948


Repository:
  rG LLVM Github Monorepo

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.retainAutoreleasedReturnValue(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
@@ -2338,14 +2338,16 @@
   // optimization level isn't -O0 since global-isel, which is currently run at
   // -O0, doesn't know about the operand bundle.
 
+  auto *oldCall = cast<llvm::CallBase>(value);
+
   // FIXME: Do this when the target isn't aarch64.
   if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
-      CGF.CGM.getTarget().getTriple().isAArch64()) {
+      CGF.CGM.getTarget().getTriple().isAArch64() &&
+      !llvm::objcarc::hasAttachedCallOpBundle(oldCall)) {
     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.327638.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210303/1a708356/attachment.bin>


More information about the cfe-commits mailing list