public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/100337] New: Should be able to pass non-present optional arguments to CO_BROADCAST
@ 2021-04-29 16:43 everythingfunctional at protonmail dot com
  2021-05-21  8:22 ` [Bug fortran/100337] " vehre at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: everythingfunctional at protonmail dot com @ 2021-04-29 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100337
           Summary: Should be able to pass non-present optional arguments
                    to CO_BROADCAST
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: everythingfunctional at protonmail dot com
  Target Milestone: ---

Attempting to write a CO_BROADCAST wrapper for a derived type, I found that
passing optional arguments to CO_BROADCAST caused a segfault if the arguments
were not present. This should be allowed. See the following minimal example

module iso_varying_string
    implicit none

    type :: varying_string
        character(len=1), allocatable :: characters(:)
    contains
        procedure :: co_broadcast => co_broadcast_varying_string
    end type
contains
    subroutine co_broadcast_varying_string(a, source_image, stat, errmsg)
        class(varying_string), intent(inout) :: a
        integer, intent(in) :: source_image
        integer, intent(out), optional :: stat
        character(len=*), intent(inout), optional :: errmsg

        integer :: string_length

        if (this_image() == source_image) string_length = size(a%characters)

        call co_broadcast(string_length, source_image, stat, errmsg)

        if (present(stat)) then
            if (stat /= 0) return
        end if

        if (this_image() /= source_image) then
            allocate(a%characters(string_length))
        end if

        call co_broadcast(a%characters, source_image, stat, errmsg)
    end subroutine
end module

program main
    use iso_varying_string, only: varying_string

    implicit none

    character(len=*), parameter :: MESSAGE = "Hello, World!"
    integer :: i
    type(varying_string) :: the_string

    if (this_image() == 1) the_string%characters = [(MESSAGE(i:i), i = 1,
len(MESSAGE))]
    call the_string%co_broadcast(1)
    print *, the_string%characters
end program

Compiling and executing with gfortran produces the following:

$ gfortran -fcoarray=single -g example.f90
$ ./a.out                                 

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

Backtrace for this error:
#0  0x7fed85487d01 in ???
#1  0x7fed85486ed5 in ???
#2  0x7fed852be94f in ???
#3  0x55cd33d21683 in __iso_varying_string_MOD_co_broadcast_varying_string
        at /home/brad/tmp/co_broadcast_optional/example.f90:20
#4  0x55cd33d21872 in MAIN__
        at /home/brad/tmp/co_broadcast_optional/example.f90:43
#5  0x55cd33d21915 in main
        at /home/brad/tmp/co_broadcast_optional/example.f90:35
zsh: segmentation fault (core dumped)  ./a.out

Note that using opencoarrays this program works, as follows:

$ caf example.f90                         
$ cafrun -n 2 ./a.out                     
 Hello, World!
 Hello, World!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-14 15:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29 16:43 [Bug fortran/100337] New: Should be able to pass non-present optional arguments to CO_BROADCAST everythingfunctional at protonmail dot com
2021-05-21  8:22 ` [Bug fortran/100337] " vehre at gcc dot gnu.org
2021-05-21 13:34 ` vehre at gcc dot gnu.org
2021-05-21 13:42 ` vehre at gcc dot gnu.org
2021-06-23  8:17 ` cvs-commit at gcc dot gnu.org
2021-06-23  8:24 ` vehre at gcc dot gnu.org
2022-02-14 15:49 ` cvs-commit at gcc dot gnu.org
2022-02-14 15:52 ` vehre at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).