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 @@ -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(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(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.retainAutoreleasedReturnValue(i8* %[[CALL1]]) + +void test_list_init() { + auto t = id{foo()}; +}