https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120483
--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- Looking at $ cat save.f90 program memain implicit none character(len=:), allocatable, save :: s1 s1 = 'ABC' if (s1(3:3) /= 'C') stop 1 end program memain $ cat nosave.f90 program memain implicit none character(len=:), allocatable :: s1 s1 = 'ABC' if (s1(3:3) /= 'C') stop 1 end program memain the diff of the .original dumps is --- save.f90.006t.original 2025-05-31 18:03:56.345527407 +0200 +++ nosave.f90.006t.original 2025-05-31 18:04:01.699589312 +0200 @@ -1,9 +1,10 @@ __attribute__((fn spec (". "))) void memain () { - static integer(kind=8) _F.s1; - static character(kind=1) * s1 = 0B; + integer(kind=8) .s1; + character(kind=1)[1:.s1] * s1; + s1 = 0B; { integer(kind=8) D.4669; void * D.4670; @@ -11,14 +12,14 @@ integer(kind=8) D.4672; if (s1 != 0B) goto L.1; - s1 = (character(kind=1) *) __builtin_malloc (3); + s1 = (character(kind=1)[1:.s1] *) __builtin_malloc (3); goto L.2; L.1:; - if (_F.s1 == 3) goto L.2; - s1 = (character(kind=1) *) __builtin_realloc ((void *) s1, 3); + if (.s1 == 3) goto L.2; + s1 = (character(kind=1)[1:.s1] *) __builtin_realloc ((void *) s1, 3); L.2:; - _F.s1 = 3; - D.4669 = _F.s1; + .s1 = 3; + D.4669 = .s1; D.4670 = (void *) s1; D.4671 = (void *) &"ABC"[1]{lb: 1 sz: 1}; D.4672 = NON_LVALUE_EXPR <D.4669> + -3; @@ -35,7 +36,7 @@ } } } - if (*s1 != 67) + if ((*s1)[3]{lb: 1 sz: 1} != 67) { _gfortran_stop_numeric (1, 0); } it seems an uninitialized length is still used for the nosave variant (which also looks suspicious) and the save case lacks the addition of the offset of the string.