I’ve come across the following question on StackOverflow, which may be related to the unexpected behavior of allocatable
by Gfortran (linked in the above post, which is still reproducible with Gfortran-14 on Godbolt). Indeed, this may be a bug of the option -fmax-stack-var-size
itself, though not sure about details.
EDIT: Here is the man page for this option.
This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables.
Also a previous thread on this option (not related to the above issue):