Skip to content

Instantly share code, notes, and snippets.

@krystophny
Created June 14, 2025 20:19
Show Gist options
  • Save krystophny/b1e1785249eacc188aa2851ed6fbe471 to your computer and use it in GitHub Desktop.
Save krystophny/b1e1785249eacc188aa2851ed6fbe471 to your computer and use it in GitHub Desktop.
GFortran 15 bug
program grow_type_array
type :: string_t
character(:), allocatable :: s
end type string_t
type(string_t) :: str
type(string_t), allocatable :: list(:)
! This works
allocate(list(0))
str = new_string("Hello!")
list = [list, str]
deallocate(list)
! This segfaults on gfortran 15.1 but works on gfortran 14
! when using -fcoarray=single compile flag
allocate(list(0))
list = [list, new_string("Hello!")]
contains
type(string_t) function new_string(s) result(out)
character(*), intent(in) :: s
out%s = s
end function new_string
end program grow_type_array
@krystophny
Copy link
Author

Fails with

$ gfortran -fcoarray=single grow_type_array.f90 && ./a.out

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

Backtrace for this error:
#0  0x7fd8ba355eef in ???
#1  0x7fd8ba3bed84 in ???
#2  0x402905 in ???
#3  0x402979 in ???
#4  0x7fd8ba33f6b4 in ???
#5  0x7fd8ba33f768 in ???
#6  0x401104 in ???
#7  0xffffffffffffffff in ???
Segmentation fault (core dumped)

Leaving out -fcoarray=single or using gfortran 14 causes no error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment