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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>:

https://gcc.gnu.org/g:d6d7e0261a0ee43c8738b964cbb2572d49d24cad

commit r15-6822-gd6d7e0261a0ee43c8738b964cbb2572d49d24cad
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Fri Jan 10 01:06:37 2025 +1100

    c++/modules: Handle chaining already-imported local types [PR114630]

    In the linked testcase, an ICE occurs because when reading the
    (duplicate) function definition for _M_do_parse from module Y, the local
    type definitions have already been streamed from module X and setup as
    regular backreferences, rather than being found with find_duplicate,
    causing issues with managing DECL_CHAIN.

    It is tempting to just skip setting up the DECL_CHAIN for this case.
    However, for the future it would be best to ensure that the block vars
    for the duplicate definition are accurate, so that we could implement
    ODR checking on function definitions at some point.

    So to solve this, this patch creates a copy of the streamed-in local
    type and chains that; it will be discarded along with the rest of the
    duplicate function after we've finished processing.

    A couple of suggested implementations from the discussion on the PR that
    don't work:

    - Replacing the `DECL_CHAIN` assertion with `(*chain && *chain != decl)`
      doesn't handle the case where type definitions are followed by regular
      local variables, since those won't have been imported as separate
      backreferences and so the chains will diverge.

    - Correcting the purviewness of GMF template instantiations to force Y
      to emit copies of the local types rather than backreferences into X is
      insufficient, as it's still possible that the local types got streamed
      in a separate cluster to the function definition, and so will be again
      referred to via regular backreferences when importing.

    - Likewise, preventing the emission of function definitions where an
      import has already provided that same definition also is insufficient,
      for much the same reason.

            PR c++/114630

    gcc/cp/ChangeLog:

            * module.cc (trees_in::core_vals) <BLOCK>: Chain a new node if
            DECL_CHAIN already is set.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/pr114630.h: New test.
            * g++.dg/modules/pr114630_a.C: New test.
            * g++.dg/modules/pr114630_b.C: New test.
            * g++.dg/modules/pr114630_c.C: New test.

    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>
    Reviewed-by: Patrick Palka <ppa...@redhat.com>

Reply via email to