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

Stefano Zaghi <stefano.zaghi at cnr dot it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stefano.zaghi at cnr dot it

--- Comment #5 from Stefano Zaghi <stefano.zaghi at cnr dot it> ---
The length of a deferred-length character function result is kept in a static
temporary, so any two threads calling such a
function through the same call site race, with -fopenmp and -frecursive too.
Seen with 11.5, 12.5, 13.4, 14.3, 15.1, 15.2 and 16.2.

    module m
    implicit none
    contains
      function text(n) result(t)
        integer, intent(in) :: n
        character(len=:), allocatable :: t
        allocate(character(len=n) :: t)
        t = repeat('x', n)
      end function text
    end module m
    program p
    use m
    implicit none
    integer :: i, k, bad
    bad = 0
    !$omp parallel do private(i) reduction(+:bad)
    do k = 1, 8
      do i = 1, 100000
        if (len(text(k)) /= k) bad = bad + 1
      end do
    end do
    print *, 'wrong lengths:', bad
    end program p

gfortran -O2 -fopenmp: "wrong lengths: 4202" (16.2.0, 8 threads; 0 expected).
-fdump-tree-original shows
`static integer(kind=8) slen.0;`. It comes from gfc_conv_procedure_call,
trans-expr.cc (16.2.0, line 8882):

          TREE_STATIC (tmp) = 1;

With TREE_ADDRESSABLE (tmp) = 1 instead (not run through the testsuite) the
program prints 0, and a library of 110000 lines
whose 16-thread output was corrupted in every run writes the same bytes as one
thread.

Reply via email to