https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126479

            Bug ID: 126479
           Summary: STORAGE_SIZE doesn't work on disassociated pointers
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikael at gcc dot gnu.org
  Target Milestone: ---

Testcase exercising STORAGE_SIZE of disassociated pointers:

program p
  implicit none
  type :: t1
    integer :: c1
  end type
  type, extends(t1) :: t2
    integer :: c2
  end type t2
  type(t2), allocatable, target :: a(:)
  class(t1), pointer :: ptr(:)
  ptr => null()
  !print *, storage_size(ptr)
  allocate(a(5))
  ptr => a
  print *, storage_size(ptr)
  ptr => null()
  print *, storage_size(ptr)
  deallocate(a)
end program

gives at execution time:
          64
          64
Enabling the commented line gives an execution time segmentation fault.
The expected outcome is:
          64
          32
and with the line uncommented:
          32
          64
          32

I think that disassociated pointers can be valid, and the example above shows
some cases where they are.

>From the standard F2023, 16.9.200 (STORAGE_SIZE):
  Arguments.
  A   shall be a data object of any type. If it is polymorphic it shall not be 
      an undefined pointer. If it is unlimited polymorphic or has any deferred
      type parameters, it shall not be an unallocated allocatable variable or a
      disassociated or undefined pointer.

In the example, `ptr' is not undefined for any call to storage_size.  It is not
unlimited polymorphic and doesn't have deferred type parameters, so the last
condition doesn't apply.  Thus, the three calls to storage_size should be
valid.

Reply via email to