[clang] [Clang][CodeGen] Track EH cleanup depth for guarded init and pop correctly (PR #199508)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 17 10:50:27 PDT 2026
ahatanak wrote:
> For non-ARC, no matter what order we do the destruction, it still blows up if you call the function more than once: the block itself gets destroyed when the first call returns, and we never run the initialization again. The only way to make it usable would be to do something like C++ lifetime extension to make the block itself have static lifetime (along the lines of how `static const A& a = A();` works).
A few thoughts:
1. This can be fixed if the block is copied via `__Block_copy` and assigned it to `b` after the static initialization. `b` then points to a heap block, so later calls are fine. But the captures have to be kept alive until the block is copied.
2. Even without the `__Block_copy`, the function is well defined if it only runs once. I don't think anything in the standard makes the code invalid just because it can't be invoked more than once.
https://github.com/llvm/llvm-project/pull/199508
More information about the cfe-commits
mailing list