diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/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(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(value); llvm::CallBase *newCall = llvm::CallBase::addOperandBundle( oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB, oldCall); newCall->copyMetadata(*oldCall); diff --git a/clang/test/CodeGenObjCXX/arc-rv-attr.mm b/clang/test/CodeGenObjCXX/arc-rv-attr.mm new file mode 100644 --- /dev/null +++ b/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()}; +}