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

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

https://gcc.gnu.org/g:35e82d8e94c92744f1d31896dcac32810f357e53

commit r16-9205-g35e82d8e94c92744f1d31896dcac32810f357e53
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