From gfortran's man page:
Adding this option will make the Fortran compiler put all local arrays, even those of unknown size onto stack memory. If your program uses very large local arrays it is possible that you will have to extend your runtime limits for stack memory on some operating systems. This flag is enabled by default at optimization level -Ofast.
This RFC provides an evaluation of the scope of work required to support -fstack-arrays as a pass responsible for moving array heap allocations to the stack.
Github issue: https://github.com/llvm/llvm-project/issues/59231
The proposed design works in most cases, the exceptions are
- Where blocks: the generated code is too complex for the pass to follow. There are multiple known bugs in the generated code so the easiest course of action is likely to be to fix this in codegen.
- Array constructors: the generated code uses realloc() because it is not always possible to tell ahead of time how large the constructed array will be. This makes it difficult to rewrite the generated code to use alloca. gfortran is able to transform this case into a stack allocation. This more complex case will be left for future work.
For more information on these two cases see the section on ConvertExpr.cpp.