https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112653
--- Comment #20 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-14 branch has been updated by Eric Botcazou <[email protected]>: https://gcc.gnu.org/g:96a242d46e4d57e41b7748469c6236a35eca7916 commit r14-12717-g96a242d46e4d57e41b7748469c6236a35eca7916 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.
