[PATCH] D41050: Fix over-release of return value of lambda implicitly converted to block
John McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 12 12:20:30 PST 2017
rjmccall added a comment.
In https://reviews.llvm.org/D41050#952720, @danzimm wrote:
> Or do we need to abide by those semantics strictly here? Could you expand on why that is, if that's the case?
The autoreleased-return-value optimization cannot be understood purely in terms of its impact on the retain count; it's a hand-off from the callee to the caller the requires a specific code-generation pattern in order to work.
Here, calling retainAutoreleasedRV in the block is necessary in order to prevent the return value from the lambda from actually being autoreleased. The block then owns a retain on the return value and must call autoreleaseRV in order to balance that out and transfer the object to its caller. The caller will hopefully also call retainAutoreleasedRV, thus completing the transfer of the return value all the way to the ultimate caller without actually performing any retains or releases.
More information about the cfe-commits