Page MenuHomePhabricator

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

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



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.


Diff Detail

Event Timeline

ahatanak created this revision.Mon, May 24, 7:54 PM
ahatanak requested review of this revision.Mon, May 24, 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() {
  %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.Thu, Jun 3, 8:49 AM

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

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

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