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

--- Comment #4 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:f2a3739d18801d6e449f94b1f026b6a30efc8957

commit r17-6488-gf2a3739d18801d6e449f94b1f026b6a30efc8957
Author: Jakub Jelinek <[email protected]>
Date:   Fri Nov 20 09:20:06 2026 +0100

    expr: Fix up bit-field handling in unions in
categorize_ctor_elements_1/count_type_elements [PR128302]

    The same PR also complains that we use TYPE_SIZE (TREE_TYPE (f))
    instead of DECL_SIZE (f) in comparisons whether the union member
    occupies the whole union or if there are some padding bits
    after it.  If there are full padding bytes after the whole
    TREE_TYPE, then we already handled it correctly, but if DECL_SIZE
    is smaller we haven't.
    In complete_ctor_at_level_p which is also used by C++ FE we don't
    have access to the ctor nor active member, so we can't do anything
    else there, so this patch just repeats the condition from that
    function for the bit-field case in unions, the rest is using
    DECL_SIZE whenever possible for union members.

    No testcase, it didn't feel right to test for the padding bytes (which is
    UB), but just watched the reported testcase and we now do clear the
    padding bits and even emit more efficient code (just set the whole 32-bit
    union to a constant instead of oring in some bits into previously
    uninitialized stack slot).

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

            PR middle-end/128302
            * expr.cc (count_type_elements): For unions compare
            DECL_SIZE (f) rather than TYPE_SIZE (TREE_TYPE (f)).
            (categorize_ctor_elements_1): Similarly.  Also force
            p_compate->sparse for ZERO_INIT_PADDING_BITS_UNIONS
            or above if active union member is a bit-field with
            padding.

    Reviewed-by: Richard Biener <[email protected]>

Reply via email to