[Bug libfortran/92836] segfault with inquire()

tkoenig at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Dec 8 15:16:00 GMT 2019


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

--- Comment #14 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Created attachment 47441
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47441&action=edit
Output of valgrind --tool=helgrind

The code from https://gcc.gnu.org/ml/fortran/2019-12/msg00020.html :


program inq
  use OMP_Lib
  implicit none
  logical :: s
  character(len=27) :: c
  integer :: i, j

  i=64
  !$omp parallel private(c,j,s)
  do while (.true.)
     if (OMP_Get_Thread_Num() < omp_get_num_threads()/2) then
        open(newUnit=j,file='test.txt',form='formatted',status='unknown')
        write (c,'(e17.10)') 1.23456d0
        write (j,*) trim(c)
        close(j)
     else
        inquire(file='test.txt',exist=s)
     end if
  end do
  !$omp end parallel
end program

certainly raises a few flags using valgrind --tool=helgrind (see attachment);
apart from the things that happen in libgomp (see PR40362), there are also
fishy things going on in libgfortran:

==4669== Possible data race during write of size 8 at 0x645E9E8 by thread #5
==4669== Locks held: 1, at address 0x645EAC0
==4669==    at 0x5099EA0: _gfortrani_new_unit (open.c:566)
==4669==    by 0x509A7FC: already_open (open.c:720)
==4669==    by 0x509A7FC: _gfortran_st_open (open.c:897)
==4669==    by 0x400BED: MAIN__._omp_fn.0 (in /tmp/a.out)
==4669==    by 0x5611065: gomp_thread_start (team.c:123)
==4669==    by 0x4C315BD: mythread_wrapper (hg_intercepts.c:389)
==4669==    by 0x5C9A723: start_thread (in /lib64/libpthread-2.22.so)
==4669==    by 0x5F9BE8C: clone (in /lib64/libc-2.22.so)
==4669== 
==4669== This conflicts with a previous read of size 8 by thread #16
==4669== Locks held: 1, at address 0x52F94C0
==4669==    at 0x50A39D1: find_file0 (unix.c:1722)
==4669==    by 0x50A39EE: find_file0 (unix.c:1741)
==4669==    by 0x50A514A: _gfortrani_find_file (unix.c:1779)
==4669==    by 0x509258C: _gfortran_st_inquire (inquire.c:803)
==4669==    by 0x400B5C: MAIN__._omp_fn.0 (in /tmp/a.out)
==4669==    by 0x5611065: gomp_thread_start (team.c:123)
==4669==    by 0x4C315BD: mythread_wrapper (hg_intercepts.c:389)
==4669==    by 0x5C9A723: start_thread (in /lib64/libpthread-2.22.so)
==4669==  Address 0x645e9e8 is 8 bytes inside a block of size 752 alloc'd
==4669==    at 0x4C2DA51: calloc (vg_replace_malloc.c:762)
==4669==    by 0x4E5D612: _gfortrani_xcalloc (memory.c:78)
==4669==    by 0x50A2B17: insert_unit (unit.c:233)
==4669==    by 0x50A2D77: get_gfc_unit (unit.c:356)
==4669==    by 0x509A788: _gfortran_st_open (open.c:889)
==4669==    by 0x400BED: MAIN__._omp_fn.0 (in /tmp/a.out)
==4669==    by 0x5611065: gomp_thread_start (team.c:123)
==4669==    by 0x4C315BD: mythread_wrapper (hg_intercepts.c:389)
==4669==    by 0x5C9A723: start_thread (in /lib64/libpthread-2.22.so)
==4669==    by 0x5F9BE8C: clone (in /lib64/libc-2.22.so)
==4669==  Block was alloc'd by thread #5

...


More information about the Gcc-bugs mailing list