]> granicus.if.org Git - clang/commit
[CodeGen][ObjC] Block captures should inherit the type of the captured
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 16 Sep 2016 00:02:06 +0000 (00:02 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 16 Sep 2016 00:02:06 +0000 (00:02 +0000)
commit23c768ab7e8ff4c862b57835d2f78dd0130d382b
treea5947bdc76fe4ea650e9a38c7ee8a59a2b39bcae
parent5a8a262055f56a6bb896e2f5616233beac2d2673
[CodeGen][ObjC] Block captures should inherit the type of the captured
field in the enclosing lambda or block.

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();
}

rdar://problem/18586386

Differential Revision: https://reviews.llvm.org/D21104

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281682 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGBlocks.h
test/CodeGenObjCXX/lambda-expressions.mm