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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Longjun Luo <[email protected]>:

https://gcc.gnu.org/g:4db36a4494a21494e56649f6f38362190b72f7b8

commit r17-6545-g4db36a4494a21494e56649f6f38362190b72f7b8
Author: Longjun Luo <[email protected]>
Date:   Thu Nov 12 03:09:07 2026 +0800

    lto: Preserve input origins before SCC unification [PR126348]

    SCC unification or prevailing-declaration replacement can redirect an
    instance's origin tree to another input's tree. The tree-to-DIE lookup
    then returns that input's DIE, while parameters and local variables
    retain their original origins.

    Save input DIE references by reader-cache index before the trees can be
    replaced. Resolve each retained instance's encoded origin through these
    references when registering it for late DWARF.

    Write saved origins explicitly in WPA and incremental-link output,
    including absent references, so later reads do not derive origins from
    merged trees.

    Tested on x86_64-pc-linux-gnu with a C/C++ checking build and
    the LTO suites (gcc.dg/lto: 2012, g++.dg/lto: 1860 expected passes),
    with no unexpected failures.

    gcc/ChangeLog:

            PR debug/126348
            * lto-streamer.h (lto_die_ref, lto_die_ref_map,
lto_origin_ref_kind,
            lto_pending_origin_ref): New.
            (lto_origin_ref_node_p): New function.
            (data_in): Add reader-cache DIE references, pending origins and
            methods to save and register them.
            (stream_read_tree_ref): Adjust declaration.
            * lto-streamer-in.cc (data_in::save_die_ref,
            data_in::register_origin_refs): New methods.
            (lto_read_tree_1): Save input DIEs and encoded origins.  Read
explicit
            saved origins.
            (lto_read_tree, lto_input_scc): Pass the reader-cache index.
            (stream_read_tree_ref): Optionally return the encoded reference.
            (lto_input_tree): Register saved origins after reading the input
trees.
            (lto_data_in_delete): Delete the temporary DIE-reference map.
            * lto-streamer-out.cc (lto_write_tree_1): Stream saved origins and
            distinguish absent origins from original tree references.
            * tree-streamer.h (streamer_read_tree_body): Adjust declaration.
            * tree-streamer-in.cc (lto_input_ts_decl_common_tree_pointers,
            lto_input_ts_block_tree_pointers, streamer_read_tree_body): Capture
            encoded abstract-origin references.

    gcc/lto/ChangeLog:

            PR debug/126348
            * lto-common.cc (unify_scc): Discard pending origins for merged
trees.
            (lto_read_decls): Register origins for retained trees at the end of
            each iteration.

    gcc/testsuite/ChangeLog:

            PR debug/126348
            * g++.dg/lto/pr126348.h: New test header.
            * g++.dg/lto/pr126348_0.C: New test.
            * g++.dg/lto/pr126348_1.C: Likewise.
            * g++.dg/lto/pr126348_2.C: Likewise.
            * g++.dg/lto/pr126348-3.h: New test header.
            * g++.dg/lto/pr126348-3_0.C: New test.
            * g++.dg/lto/pr126348-3_1.C: Likewise.
            * g++.dg/lto/pr126348-3_2.C: Likewise.

    Signed-off-by: Longjun Luo <[email protected]>

Reply via email to