<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88344>88344</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
flang-new: forcing arrays to be allocated on the heap and a possible bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zaikunzhang
</td>
</tr>
</table>
<pre>
This is related to https://github.com/llvm/llvm-project/issues/56018.
According to https://github.com/llvm/llvm-project/issues/56018 , `flang -mmlir -fdynamic-heap-array` should force dynamic arrays to be allocated on the heap. The example mentioned at https://github.com/llvm/llvm-project/issues/56018 works but the following does not.
```
! array.f90
module outprod_mod
contains
function outprod(y, z) result(x)
implicit none
real, intent(in) :: y(:), z(:)
real :: x(size(y), size(z))
integer :: i, j, n, m
m = size(y)
n = size(z)
do i = 1, m
do j = 1, n
x(i, j) = y(i) * z(j)
end do
end do
end function
end module outprod_mod
program prog
use outprod_mod, only : outprod
implicit none
integer, parameter :: k = 10000
integer :: i
real :: y(k)
y = 1.0
do i = 1, k
write (*, *) i, size(outprod(y(1:i), y(1:i)))
end do
end
```
With flang-new, it crashes with a segfault as follows.
```text
$ uname -a && flang --version && flang -fno-stack-arrays -mmlir -fdynamic-heap-array -o array array.f90 && ./array
Linux 6.5.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 10:22:43 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
flang-new version 19.0.0git (git@github.com:llvm/llvm-project.git 37c175af955f0aeab67e8c553a0a47b2ed0fdba2)
Target: x86_64-unknown-linux-gnu
Thread model: posix
... ...
1445 2088025
1446 2090916
Segmentation fault (core dumped)
```
Questions:
- How to effectively force dynamic arrays to be allocated on the heap?
- `-fdynamic-heap-array` alone cannot be recognized by the compiler. It must be `-mmlir -fdynamic-heap-array`. Is this intended?
Notes:
- `ulimit -s unlimited` seems to help, but we need a solution on flang's side.
- Compiled with Classic Flang 15.0.3 without any flags, the code runs fine.
Thank you for taking a look.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVktv4zYQ_jX0ZSCBomTZPvjgJut2gWax7WZR9LSgpJHEmCINPtZxDv3tBSnLj22yRR9BTGmGw9HMNy9ya0WnENdk_gOZ38-4d7026xcudl699Fx1s0o3xzWh94RuHnthQVgwKLnDBpyG3rm9JfmGsC1h20643ldprQfCtlJ-nR7J3ugnrB1hW2GtR0vYdl7SbJnCqHlcN3WtTSNU9z9oBsLugJS0lVx1kAyDFAaStjkqPog66ZHvE24MP5KSgu21lw202tQIJxGIuzaYUiFwKXUdndYKXI8QFKQAjz0CPvNhLxEGVE5ohQ1w95_NP2izs1B5F7_Wain1ISDTaLSgtLtFjpT09D-SLBvNT9sVvZYbdOMlgvZub3TzZdDNyK-1clwoO1KtV3XwZJIjbHkMcL4QtgKD1ktH2PKZsNUoL4a9FLVwoLTCkWWQy3BEKIcqSAsVDgdA8g0cCVtGbFYntRN1PjtJPhO2tOIFRxOi-Il8ieRkgXLYoZlOiSD3FBYVluEGAiD5PVzrjGx1zX45sxsNIu5kV4oAABoNT5cNddkIf8HqyYZVlDqOnBUQtokOP50_EQ6gaqDRI_3t-xSNC-etKI7r3ujO8AHCc-R4eyvM7kAreQxonUP8ViBv8A0n99zwAd0F7N0IA6WUvhGMv0Q1oLE7A3AcFaT0Nch3F5AORjiEkCxsE6s7PFZjsE-Bu0nYZUbyjThlzS19yZxv0H69nOL6m3A9xHaSKDzE5HZQG257tHAImxwsdi330gG3p5q16at16vDZTbVagFd8QEg4EFYSVsKpaSVf0dhQh7fsVunEOl7vklOL-k53g0SPneDSDyZtKWHbsQNeGfizUP4ZynSe0oSVSYcKjaiBsJyVfzCW0iLNks-VV87Dp4eP8PHXd-8ePj5-uf_9w-bh_R08eoQHbiBjkFGSbxgj-abI4fPjHTB4XpZfyuKbx48fPhO2jR8-tZ8JY5j8z1YpTWknXIh-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