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

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

https://gcc.gnu.org/g:95986d90c4e90691820f08f6f43d48d24cc44495

commit r17-2039-g95986d90c4e90691820f08f6f43d48d24cc44495
Author: Eric Botcazou <[email protected]>
Date:   Wed Jul 1 10:23:46 2026 +0200

    PTA: Fix wrong optimization of conditional dynamic allocation

    This is a regression present on mainline, 16, 15 and 14 branches introduced
    by the fix for PR tree-optimization/112653 (PTA and return).  What happens
    is that DSE incorrectly eliminates a call to memcpy, whose destination is
    obtained from (an equivalent of) malloc and is ultimately returned from the
    function.  But this happens only when the dynamic allocation is
conditional.

    The difference between the unconditional and conditional cases is:

    ESCAPED_RETURN = { ESCAPED NONLOCAL HEAP(30) }

    vs

    ESCAPED_RETURN = { ANYTHING }

    The fix is to apply in set_uids_in_ptset the same treatment to ANYTHING in
    the escaped return case as in the escaped case.

    gcc/
            * tree-ssa-structalias.cc (set_uids_in_ptset): If ANYTHING is
            present in the ESCAPED_RETURN solution, record that the global
            solution has an escaped heap if FROM contains a heap variable.

    gcc/testsuite/
            * gnat.dg/opt109.adb: New test.
            * gnat.dg/opt109_pkg.ads, gnat.dg/opt109_pkg.adb: New helper.

Reply via email to