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

    <tr>
        <th>Summary</th>
        <td>
            [flang] unesecarry array temporary allocation for array constructors
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          tblah
      </td>
    </tr>
</table>

<pre>
    When compiling
```
subroutine sequence(seq, n)
  integer :: n, seq(n)
 seq = [(i,i=1,n)]
end subroutine
```
Flang will generate code which allocates a temporary array on the heap, constructs the array in the temporary (`realloc()`ating to a larger temporary buffer whenever necessary), then copy the constructed elements from the temporary array to `seq`.

Why is the temporary array necessary? Could `seq` be constructed in place, therefore avoiding (multiple) allocations and copies?

gfortran 11.3.0 does not appear to memcpy into the result.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU9FuozAQ_BrzsmpklkDggYdeIn6hz4tZwCdjU9u0yt-fTHKld6oUBRnP7M7MshSCnixzK8pforxltMXZ-Tb2huasd8O9fZvZgnLLqo22k5A3IV9FJZ-__Ri23rstassQ-H1jq1hgHfhd4BWswOYBA9A28sQeRPEqitd0dYUdVn9DBX4HUdwgKcJaC7xqUdxygdcdVN4eOLYDHI1_1NUZshN8amNgYsueIoNyA8PnrNUMZIxTFDkAQeRldZ78Hch7uoOzEGeGmWlNIpWzIfpNxbC_fmD0A3NQBdaikp73wumAjagkRW0niA4IDPlk_2D02ziyh8-ZLX-wB8uKQyB_T1S8pvop_PW-d_pSwQOw4YVtDDB6t_yn4yEvOhCVTPFW8vTMZ_9_m--gw4-co3_RwdVtZjhqQP-vAm1hNZRGvev0PDrPQB9OD8mwwHrZTNSrYYHN37C1swHIDsmU5iCK7ruyaXQ-erKQ56fiJGFwHMC6CLSuTD5ZWnhRa8o-ut2B57CZ-PSXDW0xNEVDGbd5dcHLBS9Fk81tTVXfK-orHGR5yccz5VieB-pzlJgPfaZblFjIXBZ5I8uiOUlUyJKwyi-FquuzOEteSJuTMR_Lyfkp0yFs3JZNLcvMUM8m7EuEOKbPTiCmffJtwr_02xTEWRodYjgqRB3NvnkPRnmDzXJgRf4Y4jGgrwBhdP55_TUP50O2edPOMa4hrRd2ArtJx3nrT8otArvU9vl4Wb37zSoK7HYXQWC3G_kTAAD__wqBUlg">