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

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

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

commit r17-469-ga202c707bea3ff021b44aa00c0570798a30aae31
Author: Martin Jambor <[email protected]>
Date:   Tue May 12 14:59:13 2026 +0200

    sra: Fix build_user_friendly_ref_for_offset for bit-fields (PR124151)

    When SRA propagates bit-field propagations across assignments, it
    first attempts to use build_user_friendly_ref_for_offset to represent
    the expression of the new accesses and a possible scalar replacement
    so that if there are any warnings generated for it, they are as nice
    as we can make them.

    However, this can lead to situations where, despite that the new
    access has exactly the same type as the new old one, it accesses a
    (record or union): field which is just big enough for its precision,
    whereas the one we want to match has size rounded up to bytes.  This
    causes discrepancy between the recorded size of the new access and the
    size get_ref_base_and_extent reports for its expr, which trips the
    verifier.

    Unlike the previous approach which avoided propagation in the case of
    bit fields, this patch fixes build_user_friendly_ref_for_offset by
    making it also track the size it is looking at and the size it is
    looking for so that it can declare success only if these two also
    match.  Additionally, it reverts the simple bail-out fix for PR 117217
    because it is no longer necessary.  (I have verified the bug is still
    fixed though by applying the new fix on top of the last problematic
    commit.)

    gcc/ChangeLog:

    2026-04-29  Martin Jambor  <[email protected]>

            PR tree-optimization/124151
            * tree-sra.cc (build_user_friendly_ref_for_offset): Added
parameters
            CUR_SIZE and EXP_SIZE.  Added code passing the correct CUR_SIZE and
            checking it against EXP_SIZE.  Removed unused code for the case
when
            EXP_TYPE was NULL_TREE.
            (create_artificial_child_access): Adjusted the call to
            build_user_friendly_ref_for_offset.
            (propagate_subaccesses_from_rhs): Likewise.
            (propagate_subaccesses_from_rhs): Removed a check that the size of
            lchild is a multiple of BITS_PER_UNIT.
            (propagate_subaccesses_from_lhs): Likewise.

    gcc/testsuite/ChangeLog:

    2026-04-29  Martin Jambor  <[email protected]>

            PR tree-optimization/124151
            * gcc.dg/tree-ssa/pr124151.c: New test.

Reply via email to