llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[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.

Open chandankds opened this issue 2 years ago • 2 comments

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

chandankds avatar Dec 24 '23 09:12 chandankds

This behavior is conformant (F'2023 subclause 9.7.4 paragraph 6, "If any other error condition occurs, each allocate-object has a processor-dependent status..." and is intentional.

klausler avatar Dec 26 '23 22:12 klausler

Working as intended; closing bug.

klausler avatar Dec 26 '23 22:12 klausler