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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] DEALLOCATE(name-list, STAT=iostat), when some in name-list are allocated and some not, does not deallocate an allocated name that occurs after the first not-allocated name.
        </td>
    </tr>

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

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

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

<pre>
    Partially successful DEALLOCATE with STAT= specifier should deallocate all names that can be deallocated.

The GNU and Intel compilers are also lazy like that.

Testcase

```
Program test_deallocate_some
 Integer, Allocatable :: x1(:),x2(:),x3(:)
  Integer::istat
  Allocate (x1(10),x2(4),x3(5))
10  Deallocate(x2)
20 Deallocate(x1,x2,x3,stat=istat) ! istat non-zero because x2 is deallocated
  If (istat==0) Print *, "bug STAT"
  If (Allocated(x1)) Print *,"bug x1" ! x1 should have been deallocated at 20
  If (Allocated(x2)) Print *,"bug x2" ! x2 was deallocated at 10
  If (Allocated(x3)) Print *,"bug x3" ! x3 should have been deallocated att 20
End Program test_deallocate_some
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElFFvozgQxz-NeRklMmNowgMPXGlOJ63uKl3veWVgCL517Mo223Y__coOpUkfUikKNp7_b_4Mw0jv1dEQ1az8g5VtJucwWVf3kzSDND8Gn3V2eKsfpQtKav0Gfu578n6cNbQPzbdv_9w3Tw_wosIE_z41T0y04J-pV6MiB36ysx5gIKm17WUgkFqDkSfyECYZoJcGOroIGLaMt4w35_-nieDPv_8DaQb4ywTS0NvTs9LkPEgXad6Clr_eQKsflJDXevKhl54u77E7vvzS9tHZo5MnCOTD9w8f3709LbKU-UiO4T0052PZaQImGiYaeM0Z7uMaK4b3r3i1Ex-7M2uFJbHyQYb3k-a9Rgz3CZrzC2ZxQSzTekHmHKBdfUctrmfIPx3lCy5x7lN20Z5dYAUMc0gbMNZsfpGz0FEvZ0_wiqD85Xtan2eMftWCYqKNpuHRKROAYROLxhC7-XhuD8RrYbPyzu6qz-pFHM8wGXzN39tqkj8JOiJz6QtkAOQ3kuCNJLgmQXiR_jM3v8UVN7hi5YqvzH-4fzADfN2daztnQy2GSlQyozrfcVHwarfj2VTLkY-FKCrcjSSqQnY9vytRCDGM5cjzfaZq5ChyxIJXiCXf7qtyL0rc7Qq6G0pCVnA6SaW3Wv88ba07Zsr7merdncAy07Ij7dMAQRy1NMf4lss2c3WM33Tz0bOCa-WD_yAEFXSaOoekKNuLccJwH2fEJkpiAy2DRdmlUeO9l4kMxDKAMrBGL1NhLacZzjHGJtBgycf11UQyF4IIOk8m2_dznDJjIAdhIhiV8_HDCJvr8G02O11PITz79KUfGB6OKkxzt-3tieEhPvJy2Tw7-z_1geEhVdAzPKQi_g4AAP__d8WvNg">