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

            Bug ID: 103634
           Summary: Runtime crash with PACK on zero-sized arrays
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

I thought we had fixed this one (see PR31001), but maybe not completely:

program p
  implicit none
  type t
     real :: r(24) = -99.
  end type
  type(t), allocatable :: new(:), old(:)
  logical, allocatable :: mask(:)
  integer              :: n, m
! m = 1    ! works
  m = 0    ! fails
  allocate (old(m), mask(m))
  mask(:) = .false.
  n = count (mask)
  allocate (new(n))
  new(:) = pack (old, mask)
  print *, size (new)
end

% ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x151ef209949f in ???
#1  0x151ef2e263e0 in pack_internal
        at ../../../gcc-trunk/libgfortran/intrinsics/pack_generic.c:182
#2  0x401194 in p
        at /home/anlauf/gcc-bugs/pack-bug.f90:15
#3  0x401255 in main
        at /home/anlauf/gcc-bugs/pack-bug.f90:17

Reply via email to