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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Pointer deallocation for zero-size target with STAT specifier causes runtime segfault at –O0.
        </td>
    </tr>

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

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

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

<pre>
    Deallocation of zero-sized pointer target with STAT= specifier causes a runtime segmentation fault and error termination.
The GNU compiler also crashes at runtime but the Intel compiler ifx returns 173 through STAT=.

**Sample.f90**
```
Program test_zero_size_pointer
    Implicit None
    Integer :: istatus
    Integer, Pointer :: xx(:),yy(:)

    Allocate(xx(0))
    yy => xx(4:3)
    Print *,size(yy),associated(yy)
    Deallocate(yy,STAT=istatus);Print *,"yy",istatus
    Deallocate(xx,STAT=istatus);Print *,"xx",istatus

    Call s(0,4,3)
Contains
    Subroutine s(sz,lo,hi)
        Integer, Intent(In):: sz,lo,hi

        Allocate(xx(sz))    
        yy => xx(lo:hi)
        Print *,size(yy),associated(yy)
        Deallocate(yy,STAT=istatus);Print *,"yy",istatus
        Deallocate(xx,STAT=istatus);Print *,"xx",istatus
    End Subroutine
End Program     
```
**ifx output:**

```
           0 T
 yy         173
 xx           0
           0 T
 yy         173
 xx           0
```

**llvm-flang output:**

```
 0 T
free(): invalid pointer
Aborted (core dumped)

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVc9vqzgQ_mvMZdSI2OQHBw55pFn18rZSu-fKwABeGTuyh7dN__qVgSYk6WH3qREKeDzzeeb7bI_0XjUGMWOrH2y1j2RPrXVZK53ybdkmUWGrU7ZHqbUtJSlrwNbwgc4-ePWBFRytMoQOSLoGCf5R1MLL6-6ViT34I5aqVuiglL1HDxJcb0h1CB6bDg2NiLXsNYE0Fa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