Skip to content

[ObjCARC] Tolerate missing attachedcall op by ignoring the bundle. #4211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ CallInst *BundledRetainClaimRVs::insertRVCallWithColors(
Instruction *InsertPt, CallBase *AnnotatedCall,
const DenseMap<BasicBlock *, ColorVector> &BlockColors) {
IRBuilder<> Builder(InsertPt);
Function *Func = *objcarc::getAttachedARCFunction(AnnotatedCall);
assert(Func && "operand isn't a Function");
Type *ParamTy = Func->getArg(0)->getType();
Optional<Function *> Func = objcarc::getAttachedARCFunction(AnnotatedCall);
// This might be a call with an empty bundle, because contract already ran.
// In that case, we don't have to insert another call.
if (!Func)
return nullptr;

Type *ParamTy = (*Func)->getArg(0)->getType();
Value *CallArg = Builder.CreateBitCast(AnnotatedCall, ParamTy);
auto *Call =
createCallInstWithColors(Func, CallArg, "", InsertPt, BlockColors);
createCallInstWithColors(*Func, CallArg, "", InsertPt, BlockColors);
RVCalls[Call] = AnnotatedCall;
return Call;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {

if (auto *CI = dyn_cast<CallInst>(Inst))
if (objcarc::hasAttachedCallOpBundle(CI)) {
BundledInsts->insertRVCallWithColors(&*I, CI, BlockColors);
--I;
if (BundledInsts->insertRVCallWithColors(&*I, CI, BlockColors))
--I;
Changed = true;
}

Expand Down
32 changes: 32 additions & 0 deletions llvm/test/Transforms/ObjCARC/contract-rv-attr-empty-bundle.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
; RUN: opt -passes=objc-arc-contract -S < %s | FileCheck %s

; CHECK-LABEL: define void @test0() {
; CHECK: %[[CALL:.*]] = notail call i8* @foo() [ "clang.arc.attachedcall"() ]
; CHECK-NEXT: call void asm sideeffect "mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue", ""()
; CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])

define void @test0() {
%call1 = notail call i8* @foo() [ "clang.arc.attachedcall"() ]
call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call1)
ret void
}

; CHECK-LABEL: define void @test1() {
; CHECK: %[[CALL:.*]] = notail call i8* @foo() [ "clang.arc.attachedcall"() ]
; CHECK-NEXT: call void asm sideeffect "mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue", ""()
; CHECK-NEXT: call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %[[CALL]])

define void @test1() {
%call1 = notail call i8* @foo() [ "clang.arc.attachedcall"() ]
call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %call1)
ret void
}

declare i8* @foo()
declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
declare i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8*)

!llvm.module.flags = !{!0}

!0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue"}