This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][ObjC] Block captures should inherit the type of the captured field in the enclosing lambda or block
ClosedPublic

Authored by ahatanak on Jun 7 2016, 3:08 PM.

Details

Summary

This patch fixes a bug in code-gen where it uses the type of the declared variable rather than the type of the capture of the enclosing lambda or block for the block capture. For example, in the following function, code-gen currently uses i32* for the block capture "a" because "a" is passed to foo1 as a reference, but it should use i32 since the enclosing lambda captures "a" by value.

void foo1(int &a) {
  auto lambda = [a]{
    auto block1 = ^{
      i = a;
    };
    block1();
  };
  lambda();
}

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 59954.Jun 7 2016, 3:08 PM
ahatanak retitled this revision from to [CodeGen][ObjC] Block captures should inherit the type of the captured field in the enclosing lambda or block.
ahatanak updated this object.
ahatanak added a reviewer: rjmccall.
ahatanak added a subscriber: cfe-commits.
rjmccall accepted this revision.Sep 14 2016, 12:34 AM
rjmccall edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Sep 14 2016, 12:34 AM
This revision was automatically updated to reflect the committed changes.