https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79956
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |NEW Component|bootstrap |libfortran Assignee|rguenth at gcc dot gnu.org |unassigned at gcc dot gnu.org --- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> --- We do rank = GFC_DESCRIPTOR_RANK (array) - 1; (expands to ((array)->dtype & 0x07) - 1 and thus is [-1, 6]) as result rank is one less than source rank(?) and for (n = 0; n < rank; n++) { count[n] = 0; dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n); if (extent[n] <= 0) return; } thus we initialize up to dstride[5] (and we figure that out, peeling the init loop completely and never initializing dstride[5]). The innermost loop n = 0; while (count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ base -= sstride[n] * extent[n]; dest -= dstride[n] * extent[n]; n++; if (n == rank) { /* Break out of the look. */ continue_loop = 0; break; } else { count[n]++; base += sstride[n]; dest += dstride[n]; } } is peeled completely as well but we somehow are not able to optimize the remaining if (rank == 6) test to true as the dominating tests are in loops forming if (rank == 1) ; else if (rank == 2) ; else if (rank == 3) ... if (rank == 6) and that's too complicated for us to analyze. Note that with LIM enabled we run into the issue that LIM happily hoists uninitialized reads (kind of PR39612). So we'd have to optimize this before LIM runs (VRP1) where we end up with rank_396: [-1, 6] EQUIVALENCES: { rank_111 rank_387 rank_391 rank_392 rank_393 rank_394 rank_395 } (7 elements) which is ok (all equivalences have the same range). Ideally it would be [-1, 0] U [6, 6] but then the cases -1 and 0 still would not allow this to be optimized. Note that the retarray->base_addr == NULL case explicitely accesses extent[rank - 1] which means that rank != 0 as well. But nothing tells GCC about this (retarray->base_addr may not actually be NULL). Index: libgfortran/generated/parity_l8.c =================================================================== --- libgfortran/generated/parity_l8.c (revision 245968) +++ libgfortran/generated/parity_l8.c (working copy) @@ -54,6 +54,8 @@ parity_l8 (gfc_array_l8 * const restrict /* Make dim zero based to avoid confusion. */ dim = (*pdim) - 1; rank = GFC_DESCRIPTOR_RANK (array) - 1; + if (rank < 1) + runtime_error ("oops"); len = GFC_DESCRIPTOR_EXTENT(array,dim); if (len < 0) fixes this (and the warning). Can fortran people please fix this?