Sema creates a declaration for gro variable as:
auto $gro = $promise.get_return_object();
However, gro variable has to outlive coroutine frame and coroutine promise, but,
it can only be initialized after the coroutine promise was created, thus, we
split its emission in two parts: EmitGroAlloca emits an alloca and sets up
the cleanups. Later when the coroutine promise is available we initialize
the gro and set the flag that the cleanup is now active.
It doesn't seem safe to assume that a prior EHCleanupScope would be for the GRO variable, nor that it can only have one such cleanup. How about this: grab a stable EHStack iterator before you emit cleanups, grab another afterwards, and iterate over the cleanups in that range modifying them as appropriate.
Even that seems a bit fragile, though. Would it be feasible to thread the 'active' flag through EmitAutoVarCleanups (perhaps add it to AutoVarEmission)?