This is an archive of the discontinued LLVM Phabricator instance.

[ObjC][ARC] Ignore operand bundle "clang.arc.attachedcall" on a call if the call's return type is void
ClosedPublic

Authored by ahatanak on May 24 2021, 7:54 PM.

Details

Summary

Instead of trying hard to prevent global optimization passes such as deadargelim from changing the return type to void, just ignore the bundle if the return type is void. clang currently emits calls to @llvm.objc.clang.arc.noop.use, which consumes the function call result, immediately after the function call to prevent changes to the return type, but optimization passes can delete the call to @llvm.objc.clang.arc.noop.use if the function call doesn't return, which enables deadargelim to change the return type.

rdar://76671438

Diff Detail

Event Timeline

ahatanak created this revision.May 24 2021, 7:54 PM
ahatanak requested review of this revision.May 24 2021, 7:55 PM

Without this patch, the verifier fails when the following code is compiled:

$ cat test.ll

declare i8* @foo0()
define internal i8* @foo1() #0 {
  %v1 = call i8 * @foo0()
  ret i8* %v1
}

define void @test() {
entry:
  %call1 = call i8* @foo1() #0 [ "clang.arc.attachedcall"(i64 0) ]
  call void (...) @llvm.objc.clang.arc.noop.use(i8* %call1)
  ret void
}

declare i8* @llvm.objc.retain(i8*)
declare void @llvm.objc.clang.arc.noop.use(...)

attributes #0 = { noreturn }

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

$ opt -S -o - -simplifycfg -deadargelim test.ll

fhahn added a comment.Jun 3 2021, 8:49 AM

Makes sense to me! Do we need to update LangRef?

ahatanak updated this revision to Diff 351517.Jun 11 2021, 11:44 AM

Update and modify the explanation of the operand bundle in LangRef.

fhahn accepted this revision.Jun 28 2021, 1:19 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jun 28 2021, 1:19 AM