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

            Bug ID: 108233
           Summary: [Coarray] bcast to non-allocatable COMPLEX scalar
                    coarray may generate wrong result
           Product: gcc
           Version: 13.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: ---

Separated from PR69604:

program p
  implicit none
  real    :: r =  2.0,      x[*] =  5.0
  complex :: c = (3.0,4.0), z[*] = (6.0, 7.0)
  complex, allocatable ::   y[:]
  allocate (y[*])
  x = r                 ! real coarray is OK
  print *, r == x, r, x
  y = c                 ! allocatable complex scalar coarray is OK
  print *, c == y, c, y
  z = c                 ! non-allocatable complex scalar coarray is bad
  print *, c == z, c, z
  call bcast_scalar  (z, c) ! fails too
  print *, c == z, c, z
  call assign_scalar (z, c) ! this works
  print *, c == z, c, z
contains
  subroutine assign_scalar (out, in)
    complex, intent(out) :: out
    complex, intent(in)  :: in
    out = in
  end subroutine assign_scalar
  subroutine bcast_scalar (out, in)
    complex, intent(out) :: out[*]
    complex, intent(in)  :: in
    out = in
  end subroutine bcast_scalar
end

Compiling with -fcoarray=single and running gives:

 T   2.00000000       2.00000000    
 T             (3.00000000,4.00000000)             (3.00000000,4.00000000)
 F             (3.00000000,4.00000000)             (6.00000000,7.00000000)
 F             (3.00000000,4.00000000)             (6.00000000,7.00000000)
 T             (3.00000000,4.00000000)             (3.00000000,4.00000000)

For reference, Intel (and similarly NAG) give:

 T   2.000000       2.000000    
 T (3.000000,4.000000) (3.000000,4.000000)
 T (3.000000,4.000000) (3.000000,4.000000)
 T (3.000000,4.000000) (3.000000,4.000000)
 T (3.000000,4.000000) (3.000000,4.000000)

It appears that the bcast of a complexx scalar to a complex scalar coarray
does not always work.

Reply via email to