Skip to content

[Flang] Pointer deallocation for zero-size target with STAT specifier causes runtime segfault at –O0. #78391

@harishch4

Description

@harishch4

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)

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorflang:runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions