https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124661
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Mikael Morin <[email protected]>: https://gcc.gnu.org/g:1c795ee4bc6b08f16cf1ad43acac47dc7c4b6b94 commit r16-8359-g1c795ee4bc6b08f16cf1ad43acac47dc7c4b6b94 Author: Mikael Morin <[email protected]> Date: Tue Mar 31 15:34:29 2026 +0200 fortran: Give up reference factoring in case of shared tree [PR124661] When we are about to create a variable to factor a subreference of an array descriptor, check whether that subreference is shared with some of the preliminary code and abort the factoring in that case. In the example from the PR, the preliminary code contained bounds checking code and the replacement of the subreferences by fresh variables was causing those variables to be used before they were defined in that bounds checking code. PR fortran/121185 PR fortran/124661 gcc/fortran/ChangeLog: * trans-array.cc (maybe_save_ref): New wrapper function around save ref. (set_factored_descriptor_value): Use the new wrapper function. Add argument PRELIMINARY_CODE. (gfc_conv_ss_descriptor): Update caller. gcc/ChangeLog: * tree-inline.cc (debug_find_tree, debug_find_tree_1): Move and rename functions... * tree.cc (find_tree, find_tree_1): ... here. * tree-inline.h (debug_find_tree): Move renamed declaration... * tree.h (find_tree): ... here. gcc/testsuite/ChangeLog: * gfortran.dg/bounds_check_28.f90: New test. Co-authored-by: Christopher Albert <[email protected]>
