llvm / llvm/llvm-project

[flang] Spurious runtime error for DEALLOCATE of a zero-sized array section that is entire zero-size array

Open
#193,418 3 comments 0 reactions 1 assignee Claimed by @ejose02 View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang produces a spurious runtime error when deallocating a pointer to a zero-sized array section, even when that section represents the entire allocated array.

Expected Behavior: When a pointer points to a section of a zero-sized array, and that section encompasses the entire (empty) array, DEALLOCATE should succeed since the section is effectively the whole allocated object.

Actual Behavior: Flang produces a runtime error:
```
fatal Fortran runtime error: DEALLOCATE of a pointer that is not the whole content of a pointer ALLOCATE
Aborted (core dumped)
```

Reproducer:
```fortran
! test deallocate on section of a zero sized array
program deallocate_section
implicit none
integer :: size=0,lbnd=0,ubnd=100,stride=-1
integer,pointer :: a1(:),a2(:)
character(10) :: str='abcdeabcde'
allocate(a1(size))
a2 => a1(lbnd:ubnd:stride)
write(str,'(I0)') a2
deallocate(a2)
if (str /= '' ) Then
print '(a)',str
stop 'FAIL'
end if
print '("ok")'
end program deallocate_section

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.