https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95018
--- Comment #29 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- It is also interesting that this variant --- a/libgfortran/generated/in_pack_i4.c +++ b/libgfortran/generated/in_pack_i4.c @@ -88,7 +88,7 @@ internal_pack_4 (gfc_array_i4 * source) count[0]++; /* Advance to the next source element. */ index_type n = 0; - while (count[n] == extent[n]) + while (n < dim && count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ @@ -100,7 +100,6 @@ internal_pack_4 (gfc_array_i4 * source) if (n == dim) { src = NULL; - break; } else { does not get peeled.