[PATCH] D51025: [CodeGen] Fix handling of variables captured by a block that is nested inside a lambda

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 20 23:53:02 PDT 2018


ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
Herald added a subscriber: dexonsmith.

Currently IRGen doesn't handle variables captured by a block correctly when the variable is captured by reference by a lambda that encloses the block.

For example, in the following code, the type of capture 'x' in the block literal is a reference to 'id' because 'x' is captured by reference by the enclosing lambda. In this case, copy/dispose functions shouldn't be needed, but currently IRGen emits them.

  void test() {
    id x;
    [&]{ ^{ (void)x; }(); }();
  }

This happens because there are a few places in CGBlocks.cpp that use the variable's type ('id' in the example above) instead of the capture type ('id &' in the example above).


Repository:
  rC Clang

https://reviews.llvm.org/D51025

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenObjCXX/block-nested-in-lambda.cpp
  test/CodeGenObjCXX/block-nested-in-lambda.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51025.161648.patch
Type: text/x-patch
Size: 10620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180821/32d94826/attachment.bin>


More information about the cfe-commits mailing list