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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to