This is an archive of the discontinued LLVM Phabricator instance.

[CodeGenObjCXX] Fix handling of blocks in lambda
ClosedPublic

Authored by ahatanak on Apr 26 2016, 9:48 AM.

Details

Summary

This fixes a crash that occurs when a block nested in a c++ lambda captures a reference that is captured by the enclosing lambda.

rdar://problem/18586651

Diff Detail

Event Timeline

ahatanak updated this revision to Diff 55022.Apr 26 2016, 9:48 AM
ahatanak retitled this revision from to [CodeGenObjCXX] Fix handling of blocks in lambda.
ahatanak updated this object.
ahatanak added a reviewer: rjmccall.
ahatanak added a subscriber: cfe-commits.
rjmccall added inline comments.Apr 29 2016, 4:16 PM
lib/CodeGen/CGBlocks.cpp
797

Hmm. It's become increasingly clear that my original decision to expand the decl-ref logic here was a mistake. Please just turn this entire block of conditions into:

if (blockDecl->isConversionFromLambda()) {
  // The lambda capture in a lambda's conversion-to-block-pointer is
  // special; we'll simply emit it directly.
  src = Address::invalid();
} else {
  DeclRefExpr declRef(
          const_cast<VarDecl *>(variable),
          /*RefersToEnclosingVariableOrCapture*/ CI.isNested(), type,
          VK_LValue, SourceLocation());
  src = EmitDeclRefLValue(&declRef).getAddress();
}
ahatanak added inline comments.May 2 2016, 3:35 PM
lib/CodeGen/CGBlocks.cpp
797

Seems like a lot of regression tests fail if I try the code above. Currently investigating.

ahatanak updated this revision to Diff 56090.May 3 2016, 9:19 PM

Apply John's patch with a few modifications.

I had to special case __block variables and remove the line creating a load from a reference to fix the failing regression tests.

rjmccall edited edge metadata.May 4 2016, 8:41 AM

Yes, that looks good, thanks.

This revision was automatically updated to reflect the committed changes.