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

            Bug ID: 126799
           Summary: Misuse of span as element size in shmem collective
                    subroutines implementation
           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: ---

In collsub_reduce_array, the span is used to initialize the array element size:

  elem_size = GFC_DESCRIPTOR_SPAN (desc);

which is then used to dispatch to specific evaluation and assignment functions.
This is wrong, the span is the memory address difference between two
consecutive elements, the element size itself may well be smaller than that.

Testcase, fails with the shared memory coarray implementation:

program prog
  implicit none
  integer, parameter :: k = 2, n = 5
  type t
    integer(kind=k) :: c1, c2
  end type
  type(t), target :: x(n)
  integer(kind=k), pointer :: p(:)
  integer :: i, icount
  icount = num_images()
  x = [ (t(i*this_image(),i+this_image()), i=1,n) ]
  p => x%c1
  call summation(p)
  print *, icount
  print *, x%c1
  if (any(x%c1 /= [ ((icount * (icount + 1) / 2) * i, i=1,n) ])) error stop 1
contains
  subroutine summation(a)
    integer(kind=k), pointer, intent(in) :: a(:)
    call co_sum(a)
  end subroutine
end program

Output:
           8
           8
           8
           8
           8
           8
           8
     36      0    108      0    180
     36      0    108      0    180
     36      0    108      0    180
     36      0    108      0    180
     36      0    108      0    180
     36      0    108      0    180
     36      0    108      0    180
ERROR STOP 1
ERROR STOP 1
ERROR STOP 1
ERROR STOP 1
ERROR STOP 1
ERROR STOP 1
ERROR STOP 1
           8
     36      0    108      0    180
ERROR STOP 1


Expected output:
           8
           8
           8
           8
     36     72    108    144    180
     36     72    108    144    180
     36     72    108    144    180
     36     72    108    144    180
           8
           8
           8
           8
     36     72    108    144    180
     36     72    108    144    180
     36     72    108    144    180
     36     72    108    144    180

Reply via email to