http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59194
Bug ID: 59194 Summary: tsan detects race for real variables in an OMP reduction clause Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgomp Assignee: unassigned at gcc dot gnu.org Reporter: Joost.VandeVondele at mat dot ethz.ch CC: jakub at gcc dot gnu.org This seems either a bug in libgomp or tsan, not clear which one. To reproduce, libgomp must be compiled first with -fsanitize=thread as described in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55561#c15 and the following workaround applied to get tsan to work with trunk. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59188#c3 The following program: > cat test.f90 INTEGER :: i REAL :: m m=0.0 !$OMP PARALLEL DO REDUCTION(+:m) DO i=1,10 m=m+1.0 ENDDO IF (m.NE.10.0) CALL ABORT() END compiled and executed as gfortran -g -fPIE -pie -fopenmp -fsanitize=thread test.f90 ; export OMP_NUM_THREADS=2 ; ./a.out triggers the error below. Interestingly, this only happens if 'm' is decleared REAL, not if INTEGER. ================== WARNING: ThreadSanitizer: data race (pid=13744) Atomic write of size 4 at 0x7fffc5e9bfa0 by main thread: #0 __tsan_atomic32_compare_exchange_strong ??:0 (libtsan.so.0+0x000000016da2) #1 MAIN__._omp_fn.0 test.f90:0 (exe+0x000000000ed1) #2 GOMP_parallel /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/parallel.c:167 (libgomp.so.1+0x00000000e98c) #3 MAIN__ test.f90:0 (exe+0x000000000d73) #4 main ??:0 (exe+0x000000000df5) Previous read of size 4 at 0x7fffc5e9bfa0 by thread T1: #0 MAIN__._omp_fn.0 test.f90:0 (exe+0x000000000e9d) #1 gomp_thread_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/team.c:117 (libgomp.so.1+0x000000014e40) Location is stack of main thread. Thread T1 (tid=13746, running) created by main thread at: #0 pthread_create /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libsanitizer/tsan/../../../../gcc/libsanitizer/tsan/tsan_interceptors.cc:853 (libtsan.so.0+0x000000035b1a) #1 gomp_team_start /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/team.c:795 (libgomp.so.1+0x000000015686) #2 GOMP_parallel /data/vjoost/gnu/gcc_trunk/obj/x86_64-unknown-linux-gnu/libgomp/../../../gcc/libgomp/parallel.c:166 (libgomp.so.1+0x00000000e987) #3 MAIN__ test.f90:0 (exe+0x000000000d73) #4 main ??:0 (exe+0x000000000df5) SUMMARY: ThreadSanitizer: data race ??:0 __tsan_atomic32_compare_exchange_strong ==================