Skip to content

Commit 952944c

Browse files
committed
[ObjC][ARC] Don't add operand bundle clang.arc.attachedcall to a call if
the call already has the operand bundle 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 Differential Revision: https://reviews.llvm.org/D97824
1 parent 129ae51 commit 952944c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,8 +2939,12 @@ static llvm::Value *emitARCOperationAfterCall(CodeGenFunction &CGF,
29392939
ValueTransform doAfterCall,
29402940
ValueTransform doFallback) {
29412941
CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
2942+
auto *callBase = dyn_cast<llvm::CallBase>(value);
29422943

2943-
if (llvm::CallInst *call = dyn_cast<llvm::CallInst>(value)) {
2944+
if (callBase && llvm::objcarc::hasAttachedCallOpBundle(callBase)) {
2945+
// Fall back if the call base has operand bundle "clang.arc.attachedcall".
2946+
value = doFallback(CGF, value);
2947+
} else if (llvm::CallInst *call = dyn_cast<llvm::CallInst>(value)) {
29442948
// Place the retain immediately following the call.
29452949
CGF.Builder.SetInsertPoint(call->getParent(),
29462950
++llvm::BasicBlock::iterator(call));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 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
2+
3+
id foo(void);
4+
5+
// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
6+
// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 0) ]
7+
// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
8+
9+
void test_list_init() {
10+
auto t = id{foo()};
11+
}

0 commit comments

Comments
 (0)