<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56018>56018</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Segmentation fault when running 503.bwaves
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jonathon-p
      </td>
    </tr>
</table>

<pre>
    503.bwaves fails on a segmentation fault when being built without specifying the `-mmlir -fdynamic-heap-array` flag. It seems like this is due to allocating arrays with sizes determined at runtime on the stack by default, resulting in an invalid access given large enough arrays. 

When additionally passing the `-mmlir -fdynamic-heap-array` flag during compilation to allocate the arrays on the heap, 503.bwaves passes. (Additionally, increasing the stack size to accommodate the large arrays and running 503.bwaves compiled without the `-fdynamic-heap-array` flag also resulted in a pass for me.)

Should the default behavior for allocating dynamic arrays be changed so that 503.bwaves (and presumably other programs) passes without needing to specify extra flags? From what I can tell, gfortran is allocating these arrays on the heap by default. 

Small reproducer:

```
PROGRAM prog
  IMPLICIT NONE

  call sr(14, 14, 14, 14, 14)
END

SUBROUTINE sr(v, w, x, y, z)
  IMPLICIT NONE

  INTEGER, INTENT(IN) :: v,w,x,y,z
  REAL*8 a(v,w,x,y,z), b(v,w,x,y,z), c(v,w,x,y,z)
  REAL*8 arr(x, y, z)

  a(1, 1, 1, 1, 1) = 42
  b(1, 1, 1, 1, 1) = 42
  c(1, 1, 1, 1, 1) = 42
  arr(1, 1, 1) = 42
END
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVV9vmzAQ_zTk5ZSIAEnJAw9pm0yRtnRKW-3ZwAHeDES2SZd--t050FK1qzYJOQbf3e-Pz07a5udk4Yez9Emc0EAhpDLQNiDAYFljY4WV9FqITll4qrCBFGVTQtpJ_iBt1XYWzBEzWZx5wVYI3tKf1rWSGqZFfm5ELbNpheI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