[clang] [clang] Fix self-capturing `__block` variables (PR #89475)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 4 13:07:30 PDT 2024
================
@@ -2764,6 +2794,9 @@ void CodeGenFunction::emitByrefStructureInit(const AutoVarEmission &emission) {
auto layoutInfo = CGM.getObjCRuntime().BuildByrefLayout(CGM, type);
storeHeaderField(layoutInfo, getPointerSize(), "byref.layout");
}
+
+ if (emission.NeedsInitOnHeap)
+ emitByrefInitOnHeap(pointer);
----------------
ille-apple wrote:
Updated to add the flag. It's not all that bad.
In fact, if, as I suggested in my last comment, we want to support the byref lingering after unwinding, then there *must* be some kind of runtime state – to track whether whoever drops the last reference needs to run the destructor. It would be more natural for the Blocks runtime to track that state rather than relying on compiler-generated code, but the state has to live somewhere.
If, on the other hand, we don't want to support the byref lingering after unwinding, then I could go back to the idea of mutating the existing `flags` field. In that scenario, the existence of runtime state would be unnecessary, but the implementation would be relatively unobtrusive.
https://github.com/llvm/llvm-project/pull/89475
More information about the cfe-commits
mailing list