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

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Richard Biener
<[email protected]>:

https://gcc.gnu.org/g:5e8bef95e4b4e3fc3fbf180405e26f9b3bdfe738

commit r16-9555-g5e8bef95e4b4e3fc3fbf180405e26f9b3bdfe738
Author: Patrick Palka <[email protected]>
Date:   Wed Aug 12 15:58:39 2026 -0400

    c++: do not hash TYPENAME_TYPEs on pointers [PR124811]

    typename_htab is written to a precompiled header.  A hash table is
    streamed out slot array and all: gt_pch_nx() relocates the pointers
    inside the entries but leaves every entry in the slot it happened to
    occupy.  typename_hasher hashed on the addresses of the scope and the
    fullname, so the slots were chosen from addresses that ASLR randomises
    in the process writing the header, and they no longer correspond to the
    hash of anything once the header has been read back at a different
    address.

    Lookups then find a restored TYPENAME_TYPE only when it happens to lie
    on the probe sequence of the slot the new hash points at, so most miss
    and build a duplicate, and which ones miss depends on the layout the
    writing process had.  That makes a compile using a PCH differ from the
    same compile without one, and differ from itself between runs: the
    duplicates consume DECL_UIDs, every later DECL_UID shifts, and
    var-tracking hashes on DECL_UID, so .debug_loclists comes out different.

    Hash on TYPE_UID instead, which the header preserves, and use
    iterative_hash_template_arg to properly hash fullname which can be an
    arbitrary TEMPLATE_ID_EXPR.  (It's important to hash the fullname instead
    of just the name for sake of the PR c++/65328 compile-time-hog testcase.)

            PR c++/124811

    gcc/cp/ChangeLog:

            * decl.cc (typename_hasher::hash): Instead of pointer hashing,
            hash TYPE_HASH of context and use iterative_hash_template_arg
            to hash fullname.

    Co-authored-by: Bernhard M. Wiedemann <[email protected]>
    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit cc08be7bf549072bf3699a57d3d37222e8c1087d)

Reply via email to