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

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

https://gcc.gnu.org/g:04781c88dc80b5dd33264939b389090f6b6cc2bc

commit r17-5404-g04781c88dc80b5dd33264939b389090f6b6cc2bc
Author: Jakub Jelinek <[email protected]>
Date:   Tue Oct 20 12:14:35 2026 +0200

    gimple-range-fold: Fix/workaround C++ PMF types in
accumulate_range_from_component_ref [PR127685]

    The recent gimple-range-fold.cc changes broke various C++ projects.
    The problem is that the C++ FE tends to create different RECORD_TYPEs
    for pointer-to-member functions types, each time it is a type with
    __pfn and __delta members, the latter always ptrdiff_t type, the
    former some pointer to METHOD_TYPE.
    Now, accumulate_range_from_component_ref searches for exact FIELD_DECL
    pointer equality, if it doesn't find it, it assumes missing initializer.
    With the C++ FE possibly creating more types like that, we can run into
    mismatches, where the CONSTRUCTOR uses one of the types and the fld
FIELD_DECL
    is from a different RECORD_TYPE.  Most of the GIMPLE opts can deal with
    it just fine, e.g. gimple-fold.cc fold_ctor* etc. just rely on offsets
    and sizes.  Now, in the C++ case, the different types even have the
    same TYPE_CANONICAL, so they are considered equivalent by the middle-end.
    Thus, the following patch keeps using FIELD_DECL pointer equality for
    the common case where the CONSTRUCTOR and fld agree on the same
    RECORD_TYPE/UNION_TYPE/QUAL_UNION_TYPE, if they are different but
    have the same TYPE_CANONICAL, it falls back to using bit offset/bit size
    comparison (and punts on variable length structures, too complicated to
    verify that), and if even TYPE_CANONICAL is different, punts as well.

    2026-10-20  Jakub Jelinek  <[email protected]>

            PR c++/127685
            * gimple-range-fold.cc
            (ctor_ref_range::accumulate_range_from_component_ref): Workaround
            for the case where the fld FIELD_DECL isn't from the same aggregate
            type as the CONSTRUCTOR, but a canonically compatible one -
fallback
            to bit offset/size comparisons.

            * g++.dg/torture/pr127685.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to