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

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 27 11:00:15 PDT 2017


ahatanak created this revision.

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


https://reviews.llvm.org/D32601

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-foreach.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32601.96940.patch
Type: text/x-patch
Size: 7685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170427/d42eb8dd/attachment.bin>


More information about the cfe-commits mailing list