<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62354>62354</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Allocatable automatic deallocation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiranchandramohan
</td>
</tr>
</table>
<pre>
See Fortran 2018 standard: "9.7.3.2 Deallocation of allocatable variables" point 2:
When the execution of a procedure is terminated by execution of a RETURN or END statement, an unsaved
allocatable local variable of the procedure retains its allocation and definition status if it is a function result or a
subobject thereof; otherwise, if it is allocated it will be deallocated.
This is currently not implemented and does not have a TODO. This causes:
- memory leaks in program relying on this feature.
- lack of type finalization for allocatable that require it.
This should be implemented in ConvertVariable.cpp here: https://github.com/llvm/llvm-project/blob/658595d031f726047f6c1a19efefc5e3d265416a/flang/lib/Lower/ConvertVariable.cpp#L791, in a similar way to what is done for local objects that require finalization (see the code below `if needEndFinalization`), except deallocation must be added to the function context cleanups.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlM-O2zYQxp-GvgwiUKQk2wcdnOz6FCRAum3PI3JksUuRKv_Y6z59QTm76y16CSBApMiZ-c03H4QxmpMj6ln7mbUPG8xp8qF_NgGdmtDpgLOf0G0Gr6_9b0Rw9CEFdCB4vYOY0GkMmskDMCH21baSlYAHQmu9wmS8Az_Czx0OluCMwZRFZELA4o1LIJg8MF6ePydykCYCeiGV38JhCV6RzoHAREgUZuMwkYbh-t-bPx6ffv_xDXyAx28PhS_RTC4x8QXQQXYRz6QZP9wjlZV9Ayt5CsJ7zUAJjYtgUoS7xtBp0DQaZ9ZtqZUjmBFMKpgIY3ZqPQoUs00FChk_xDz44S9SqZQJ5EcmP4Mv64uJVEjfc9yqkS77i7EWBgJNb5-rm2xPk4nlusohkEv2Cs4nMPNi1-ZJ31g9xfVgwjMBwtP3h-8VrLEKc6R4G8MnmGn24QqW8DmCcUWJU8AZAtmrcSfwZUYmwkiYcqBqDbKonlfprgvBaBxa889Np7H0fSd3mjBBoL-zKfNM9z3EyWerS5P38MbBF-_OFNIfP2dUqWWBIl4x3pTSsrKLIxPHk0lTHirlZyaO1p5fX5-W4IvoTBwH6wcmjl27a_et5rIet6LjzXbsVI31nkYaVUtSi65t6g6ZOI4W3akkMiXwq79QYOL4P1BMyK_bfb0O0QFCNLOxGOCCV0geLqV1E0F7R6suN-vd7BA_KvNBQyZ2kWj1pfKaYCDrL8A6bkZwRPrR6ePdfdZxJvaFgl4ULendMyXZnGMqGqPWpAtWSftmVuVdopcEyhK6vMRqo3up93KPG-rrbicayetWbqa-EdvdXjR60Lyu-a7ju53u2kZI1dS8a-XG9IILyRvR1rIRUlYK-Z645LRFtas7zRpOMxpblQlVPpw2JsZMfSdk22wsDmTj668p9OsYh3yKrOHWxBTfw5JJlvrDncswJz9jMupD75scbP_LhlmhYrFM4fo3AAD__9nFxuU">