This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][ObjC] Don't retain/release capture objects at block creation that are const-qualified
ClosedPublic

Authored by ahatanak on Apr 27 2017, 11:00 AM.

Details

Summary

When a block captures an ObjC object pointer, clang emits a retain/release pair to prevent prematurely destroying the object the pointer points to before the block is called or copied.

When the captured object pointer is const-qualified, we can avoid emitting the retain/release pair since the pointer variable cannot be modified in the scope in which the block literal is introduced.

void test(const id x) {
  callee(^{ (void)x; });
}

This patch implements that optimization.

rdar://problem/28894510

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak created this revision.Apr 27 2017, 11:00 AM

There is a comment in test/CodeGenObjC/arc-foreach.m that states the variable introduced by fast enumeration should be retained, but I don't think that is needed?

rjmccall accepted this revision.Apr 27 2017, 11:45 AM

I agree, this seems reasonable. LGTM.

This revision is now accepted and ready to land.Apr 27 2017, 11:45 AM
This revision was automatically updated to reflect the committed changes.