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

            Bug ID: 117473
           Summary: Issue with OpenMP workshare and -fsanitize=thread
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

Created attachment 59547
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59547&action=edit
Reproducer

This may be a dup of pr66553 or not, but I am reporting this anyway.

The attached code runs fine when compiled with

gfc-15 -fopenmp -O2 -g gfc-omp-workshare.f90 -fsanitize=thread

when executing with OMP_NUM_THREADS=1:

 Max.threads:           1
 -0.16594849976231613        2.8431552110569240E-002

However, with more threads I get a sanitizer warning:

OMP_NUM_THREADS=2 ./a.out  Max.threads:           2
==================
WARNING: ThreadSanitizer: data race (pid=6436)
  Read of size 8 at 0x72cc00044610 by main thread (mutexes: write M0):
    #0 test /home/anlauf/gcc-bugs/gfc-omp-workshare.f90:19 (a.out+0x4040b1)
    #1 main /home/anlauf/gcc-bugs/gfc-omp-workshare.f90:2 (a.out+0x402d95)

  Previous write of size 8 at 0x72cc00044610 by thread T1:
    #0 spline_init_vec.0._omp_fn.0
/home/anlauf/gcc-bugs/gfc-omp-workshare.f90:45 (a.out+0x40381a)
    #1 gomp_thread_start ../../../gcc-trunk/libgomp/team.c:129
(libgomp.so.1+0x22c97)

  Location is heap block of size 101400 at 0x72cc00038000 allocated by main
thread:
    #0 malloc
../../../../gcc-trunk/libsanitizer/tsan/tsan_interceptors_posix.cpp:665
(libtsan.so.2+0x56917)
    #1 test /home/anlauf/gcc-bugs/gfc-omp-workshare.f90:9 (a.out+0x403a3a)
    #2 main /home/anlauf/gcc-bugs/gfc-omp-workshare.f90:2 (a.out+0x402d95)

  Mutex M0 (0x7258000003e0) created at:
    #0 pthread_mutex_lock
../../../../gcc-trunk/libsanitizer/tsan/tsan_interceptors_posix.cpp:1341
(libtsan.so.2+0x5af6e)
    #1 __gthread_mutex_lock ../libgcc/gthr-default.h:795 (a.out+0x40c72b)
    #2 insert_unit ../../../gcc-trunk/libgfortran/io/unit.c:250
(a.out+0x40c72b)

  Thread T1 (tid=6438, running) created by main thread at:
    #0 pthread_create
../../../../gcc-trunk/libsanitizer/tsan/tsan_interceptors_posix.cpp:1022
(libtsan.so.2+0x5c0f5)
    #1 gomp_team_start ../../../gcc-trunk/libgomp/team.c:859
(libgomp.so.1+0x2329f)
    #2 main /home/anlauf/gcc-bugs/gfc-omp-workshare.f90:2 (a.out+0x402d95)

SUMMARY: ThreadSanitizer: data race
/home/anlauf/gcc-bugs/gfc-omp-workshare.f90:19 in test
==================
 -0.16594849976231613        2.8431552110569240E-002


So is this a bug in the program source code, or a false positive in the
thread sanitizer?

Reply via email to