This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by ahatanak on Aug 20 2018, 11:53 PM.

Details

Summary

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).

Diff Detail

Repository
rC Clang

Event Timeline

ahatanak created this revision.Aug 20 2018, 11:53 PM
rjmccall accepted this revision.Aug 21 2018, 1:32 PM

LGTM.

This revision is now accepted and ready to land.Aug 21 2018, 1:32 PM
This revision was automatically updated to reflect the committed changes.
lib/CodeGen/CGBlocks.cpp