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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

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

commit r15-8059-gd0d7c6632c2913c0243f048a15ff64aec6b6232e
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Mar 14 15:31:47 2025 +0100

    c, c++: Set DECL_NOT_GIMPLE_REG_P on *PART_EXPR operand on lhs of
MODIFY_EXPR [PR119120]

    The PR119190 patch I've posted regresses the PR119120 testcase (not adding
    to testsuite, as it is fairly hard to scan for that problem).
    The issue is that for the partial setting of _Complex floating vars
    through __real__ on it first and __imag__ later (or vice versa) and since
    we forced all complex vars into SSA form we often have undefined (D)
    arguments of those COMPLEX_EXPRs.  When we don't DCE them (for -O0 debug
    info reasons), their expansion will copy both the real and imag parts
    using the floating mode and on some targets like 387 that copying alone can
    unfortunately trigger exceptions on sNaNs or other problematic bit patterns
    and for uninitialized memory it can be triggered randomly based on whatever
    is on the stack before.

    The following patch sets DECL_NOT_GIMPLE_REG_P flag in the FEs during
    genericization.
    I think Fortran doesn't have a way to modify just real or just complex
    part separately.

    The patch is for code like
              _ComplexT __t;
              __real__ __t = __z.real();
              __imag__ __t = __z.imag();
              _M_value *= __t;
              return *this;
    at -O0 which used to appear widely even in libstdc++ before GCC 9
    and happens in real-world code.  At -O0 for debug info reasons (see
    PR119190) we don't want to aggressively DCE statements and when we
    since r0-100845 try to rewrite vars with COMPLEX_TYPE into SSA form
    aggressively, the above results in copying of uninitialized data
    when expanding COMPLEX_EXPRs added so that the vars can be in SSA form.
    The patch detects during genericization the partial initialization and
    doesn't rewrite such vars to SSA at -O0.  This has to be done before
    gimplification starts, otherwise e.g. the attached testcase ICEs.

    2025-03-14  Jakub Jelinek  <ja...@redhat.com>

            PR target/119120
            * c-gimplify.cc (c_genericize_control_r): Set DECL_NOT_GIMPLE_REG_P
            on {REAL,IMAG}PART_EXPR is_gimple_reg operand at -O0 if it is lhs
            of a MODIFY_EXPR.

            * cp-gimplify.cc (cp_genericize_r): Set DECL_NOT_GIMPLE_REG_P
            on {REAL,IMAG}PART_EXPR is_gimple_reg operand at -O0 if it is lhs
            of a MODIFY_EXPR.

            * c-c++-common/pr119120.c: New test.

Reply via email to