https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889
--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Mikael Morin <mik...@gcc.gnu.org>: https://gcc.gnu.org/g:3c26783bf6fd15a134a424e8c108d1dc8df3fc44 commit r16-2249-g3c26783bf6fd15a134a424e8c108d1dc8df3fc44 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Tue Jul 15 09:58:44 2025 +0200 fortran: Amend descriptor bounds init if unallocated Always generate the conditional initialization of unallocated variables regardless of the basic variable allocation tracking done in the frontend and with an additional always false condition. The scalarizer used to always evaluate array bounds, including in the case of unallocated arrays on the left hand side of an assignment. This was (correctly) causing uninitialized warnings, even if the uninitialized values were in the end discarded. Since the fix for PR fortran/108889, an initialization of the descriptor bounds is added to silent the uninitialized warnings, conditional on the array being unallocated. This initialization is not useful in the execution of the program, and it is removed if the compiler can prove that the variable is unallocated (in the case of a local variable for example). Unfortunately, the compiler is not always able to prove it and the useless initialization may remain in the final code. Moreover, the generated code that was causing the evaluation of uninitialized variables has ben changed to avoid them, so we can try to remove or revisit that unallocated variable bounds initialization tweak. Unfortunately, just removing the extra initialization restores the warnings at -O0, as there is no dead code removal at that optimization level. Instead, this change keeps the initialization and modifies its guarding condition with an extra always false variable, so that if optimizations are enabled the whole initialization block is removed, and if they are disabled it remains and is sufficient to prevent the warning. The new variable requires the code generation to be done earlier in the function so that the variable declaration and usage are in the same scope. As the modified condition guarantees the removal of the block with optimizations, we can emit it more broadly and remove the basic allocation tracking that was done in the frontend to limit its emission. gcc/fortran/ChangeLog: * gfortran.h (gfc_symbol): Remove field allocated_in_scope. * trans-array.cc (gfc_array_allocate): Don't set it. (gfc_alloc_allocatable_for_assignment): Likewise. Generate the unallocated descriptor bounds initialisation before the opening of the reallocation code block. Create a variable and use it as additional condition to the unallocated descriptor bounds initialisation.