https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103328

--- Comment #23 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <ia...@gcc.gnu.org>:

https://gcc.gnu.org/g:0847ad33b908af88bca1e6980d0b977316d05e18

commit r12-7971-g0847ad33b908af88bca1e6980d0b977316d05e18
Author: Benno Evers <benno.ev...@tenzir.com>
Date:   Sat Apr 2 17:22:33 2022 +0100

    c++: Fix ICE due to shared BLOCK node in coroutine generation [PR103328]

    When finishing a function that is a coroutine, the function is
    transformed into a "ramp" function, and the original user-provided
    function body gets moved into a newly created "actor" function.

    In this case `current_function_decl` points to the ramp function,
    but `current_binding_level->blocks` would still point to the
    scope block of the user-provided function body in the actor function,
    so when the ramp function was finished during `poplevel()` in decl.cc,
    we could end up with that block being reused as the `DECL_INITIAL()` of
    the ramp function:

       subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
       // [...]
       DECL_INITIAL (current_function_decl) = block ? block : subblocks;

    This block would then be independently modified by subsequent passes
    touching either the ramp or the actor function, potentially causing
    an ICE depending on the order and function of these passes.

    gcc/cp/ChangeLog:

            PR c++/103328
            * coroutines.cc (morph_fn_to_coro): Reset
            current_binding_level->blocks.

    gcc/testsuite/ChangeLog:

            PR c++/103328
            * g++.dg/coroutines/pr103328.C: New test.

    Co-Authored-By: Iain Sandoe <i...@sandoe.co.uk>

Reply via email to