Skip to content

Commit 807732b

Browse files
committed
[ObjC][ARC] Replace uses of ObjC intrinsics that are arguments of
operand bundle "clang.arc.attachedcall" with ObjC runtime functions The existing code only handles the case where the intrinsic being rewritten is used as the called function pointer of a call/invoke. (cherry picked from commit 1fe8993)
1 parent f3f21c4 commit 807732b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
1515
#include "llvm/Analysis/ObjCARCInstKind.h"
16+
#include "llvm/Analysis/ObjCARCUtil.h"
1617
#include "llvm/CodeGen/Passes.h"
1718
#include "llvm/IR/Function.h"
1819
#include "llvm/IR/IRBuilder.h"
@@ -91,7 +92,20 @@ static bool lowerObjCCall(Function &F, const char *NewFn,
9192
CallInst::TailCallKind OverridingTCK = getOverridingTailCallKind(F);
9293

9394
for (auto I = F.use_begin(), E = F.use_end(); I != E;) {
94-
auto *CI = cast<CallInst>(I->getUser());
95+
auto *CB = cast<CallBase>(I->getUser());
96+
97+
if (CB->getCalledFunction() != &F) {
98+
objcarc::ARCInstKind Kind = objcarc::getAttachedARCFunctionKind(CB);
99+
(void)Kind;
100+
assert((Kind == objcarc::ARCInstKind::RetainRV ||
101+
Kind == objcarc::ARCInstKind::ClaimRV) &&
102+
"use expected to be the argument of operand bundle "
103+
"\"clang.arc.attachedcall\"");
104+
I++->set(FCache.getCallee());
105+
continue;
106+
}
107+
108+
auto *CI = cast<CallInst>(CB);
95109
assert(CI->getCalledFunction() && "Cannot lower an indirect call!");
96110
++I;
97111

llvm/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
; Make sure calls to the objc intrinsics are translated to calls in to the
44
; runtime
55

6+
declare i8* @foo()
7+
declare i32 @__gxx_personality_v0(...)
8+
69
define i8* @test_objc_autorelease(i8* %arg0) {
710
; CHECK-LABEL: test_objc_autorelease
811
; CHECK-NEXT: entry
@@ -153,6 +156,30 @@ entry:
153156
ret i8* %0
154157
}
155158

159+
define void @test_objc_retainAutoreleasedReturnValue_bundle() {
160+
; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue_bundle(
161+
; CHECK-NEXT: call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_retainAutoreleasedReturnValue) ]
162+
call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
163+
ret void
164+
}
165+
166+
define void @test_objc_retainAutoreleasedReturnValue_bundle_invoke() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
167+
; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue_bundle_invoke(
168+
; CHECK-NEXT: entry
169+
; CHECK-NEXT: invoke i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_retainAutoreleasedReturnValue) ]
170+
entry:
171+
invoke i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
172+
to label %invoke.cont unwind label %lpad
173+
174+
invoke.cont:
175+
ret void
176+
177+
lpad:
178+
%1 = landingpad { i8*, i32 }
179+
cleanup
180+
resume { i8*, i32 } %1
181+
}
182+
156183
define i8* @test_objc_retainBlock(i8* %arg0) {
157184
; CHECK-LABEL: test_objc_retainBlock
158185
; CHECK-NEXT: entry
@@ -193,6 +220,13 @@ entry:
193220
ret i8* %0
194221
}
195222

223+
define void @test_objc_unsafeClaimAutoreleasedReturnValue_bundle() {
224+
; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue_bundle(
225+
; CHECK-NEXT: call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_unsafeClaimAutoreleasedReturnValue) ]
226+
call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
227+
ret void
228+
}
229+
196230
define i8* @test_objc_retainedObject(i8* %arg0) {
197231
; CHECK-LABEL: test_objc_retainedObject
198232
; CHECK-NEXT: entry

0 commit comments

Comments
 (0)