[PATCH] D58164: Block+lambda: allow reference capture

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 14 17:23:51 PDT 2019


ahatanak added a comment.

I think I now have a better idea of what's causing the crash in IRGen.

The root of the problem is that, when `RebuildLambdaScopeInfo` is called to rebuild the scope info for the generic lambda, the type of the captured variable (`s` in `test2` and `test3` in `test/CodeGenObjCXX/block-nested-in-lambda.mm`) is passed to  `addCapture`, which is different from the type of the non-static member of the closure object. For example, the member type of the generic lambda in `test2` is `S&` whereas the type of variable `s` is `S`. `Sema::ActOnBlockStmtExpr` in SemaExpr.cpp uses the type passed to `addCapture` to determine whether copying from the lambda member to the field in the block structure requires a copy constructor, but since it isn't passed the correct type, it incorrectly determines that a copy constructor is needed when the capture is a by-reference capture (for example, in `test2`) and isn't needed when the capture is a by-copy capture (for example, in `test3`), which causes crashes in IRGen.

I think the fix is to pass the correct capture type, which I think is whatever `I->getType()` returns, to `addCapture` in `RebuildLambdaScopeInfo`, but I'm wondering whether there is a reason `VD->getType()` has to be called here when the other two cases (this and VLA) uses `I->getType()`.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58164/new/

https://reviews.llvm.org/D58164





More information about the cfe-commits mailing list