[Bug libfortran/126776] New: CO_MIN/CO_MAX intrinsics not implemented for character arguments

dobonachea at lbl dot gov via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126776

            Bug ID: 126776
           Summary: CO_MIN/CO_MAX intrinsics not implemented for character
                    arguments
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dobonachea at lbl dot gov
                CC: damian at archaeologic dot codes
  Target Milestone: ---

Created attachment 65286
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65286&action=edit
Fortran source code testing CO_MIN and CO_MAX for character arg

The CO_MIN and CO_MAX intrinsics are not implemented for character-typed
arguments.

F2023 16.9.55 and 16.9.56 specifies the A argument for CO_MAX and CO_MIN:

> Arguments
>    A     shall be of type integer, real, or character. ...

Demonstration:

---------------------------------------------------------

cgpu$ cat co_char3.F90 
program test_co_char
  implicit none
  character(len=10) :: val_min, val_max

  ! Assign a unique character to each image
  ! char(65) is 'A' in ASCII.
  val_min = repeat(char(65 + (num_images() - this_image())), len(val_min))
  write (*,'(I2,A,A)') this_image(), ": initial val_min: ", val_min

  val_max = repeat(char(65 + this_image()), len(val_min))
  write (*,'(I2,A,A)') this_image(), ": initial val_max: ", val_max


  ! Find the minimum character across all images
  call co_min(val_min)

  ! Find the maximum character across all images
  call co_max(val_max)

  sync all
  ! Print the results from image 1
  if (this_image() == 1) then
    print *, "co_min result:    ", val_min
    print *, "co_max result:    ", val_max
  end if

end program


cgpu$ gfortran --version
GNU Fortran (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


cgpu$ gfortran -fcoarray=lib co_char.F90 -lcaf_shmem && env
GFORTRAN_NUM_IMAGES=1 ./a.out 
Fortran runtime error: min not available for type/kind combination
ERROR: Image 1(pid: 3759195) failed with signal 0, exitstatus 1.

cgpu$ gfortran -fcoarray=lib co_char.F90 -lcaf_shmem && env
GFORTRAN_NUM_IMAGES=4 ./a.out 
Fortran runtime error: min not available for type/kind combination
Fortran runtime error: Fortran runtime error: Fortran runtime error: min not
available for type/kind combinationmin not available for type/kind
combinationmin not available for type/kind combination


ERROR: Image 3(pid: 3759204) failed with signal 0, exitstatus 1.
ERROR: Image 2(pid: 3759203) failed with signal 0, exitstatus 1.
ERROR: Image 1(pid: 3759202) failed with signal 0, exitstatus 1.
ERROR: Image 4(pid: 3759205) failed with signal 0, exitstatus 1.


---------------------------------------------------------

Here is the correct answer, from flang version 23.1.0-rc2:

cgpu$ flang -fcoarray co_char3.F90 -L <redacted>/lib -lcaffeine-smp-seq
-lgasnet-smp-seq && env GASNET_PSHM_NODES=4 a.out 
warning: Support for multi image Fortran features is still experimental and in
development.
 2: initial val_min: CCCCCCCCCC
 3: initial val_min: BBBBBBBBBB
 2: initial val_max: CCCCCCCCCC
 3: initial val_max: DDDDDDDDDD
 1: initial val_min: DDDDDDDDDD
 1: initial val_max: BBBBBBBBBB
 4: initial val_min: AAAAAAAAAA
 4: initial val_max: EEEEEEEEEE
 co_min result:    AAAAAAAAAA
 co_max result:    EEEEEEEEEE

And from NAG 7.2:

headroom$ nagfor -coarray co_char3.F90 && env NAGFORTRAN_NUM_IMAGES=4 a.out 
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7238
[NAG Fortran Compiler normal termination]
 1: initial val_min: DDDDDDDDDD
 1: initial val_max: BBBBBBBBBB
 3: initial val_min: BBBBBBBBBB
 3: initial val_max: DDDDDDDDDD
 4: initial val_min: AAAAAAAAAA
 4: initial val_max: EEEEEEEEEE
 2: initial val_min: CCCCCCCCCC
 2: initial val_max: CCCCCCCCCC
 co_min result:    AAAAAAAAAA
 co_max result:    EEEEEEEEEE
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.