[Bug 267768] Simple OpenMP example with thread sanitizer (-fsanitize=thread)

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 14 Nov 2022 19:08:45 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267768

            Bug ID: 267768
           Summary: Simple OpenMP example with thread sanitizer
                    (-fsanitize=thread)
           Product: Base System
           Version: 13.1-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: misc
          Assignee: bugs@FreeBSD.org
          Reporter: yuri@freebsd.org
 Attachment #238078 text/plain
         mime type:

Created attachment 238078
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=238078&action=edit
openmp.cpp

The attached code crashes when compiler like this:
> c++ openmp.cpp -fsanitize=thread -g -fopenmp

The executable SEDVs.
But in debugger it prints this:
(gdb) r
Starting program: /usr/home/yuri/Downloads/a.out 
Warning: please export TSAN_OPTIONS='ignore_noninstrumented_modules=1' to avoid
false positive reports from the OpenMP runtime!
[New LWP 464093 of process 56986]
[New LWP 464094 of process 56986]
[New LWP 464095 of process 56986]
[New LWP 464096 of process 56986]
[Detaching after fork from child process 56987]
==================
WARNING: ThreadSanitizer: data race (pid=56986)
  Atomic read of size 1 at 0x7b6800001740 by main thread:
    #0 pthread_mutex_lock
/disk-samsung/freebsd-src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:4324:3
(a.out+0x27a256)
    #1 __kmp_lock_suspend_mx
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp:1381:16
(libomp.so+0xcd206)
    #2 void __kmp_resume_template<kmp_flag_64<false, true> >(int,
kmp_flag_64<false, true>*)
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp:1594:3
(libomp.so+0xcd206)

  Previous write of size 1 at 0x7b6800001740 by thread T2:
    #0 _pthread_mutex_init
/disk-samsung/freebsd-src/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1316:3
(a.out+0x2655eb)
    #1 __kmp_suspend_initialize_thread
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp:1348:14
(libomp.so+0xcbc27)

  Location is heap block of size 1504 at 0x7b6800001200 allocated by main
thread:
    #0 malloc
/disk-samsung/freebsd-src/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:667:5
(a.out+0x262e8e)
    #1 ___kmp_allocate_align(unsigned long, unsigned long)
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/kmp_alloc.cpp:1882:25
(libomp.so+0x54d3c)
    #2 ___kmp_allocate
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/kmp_alloc.cpp:1934:9
(libomp.so+0x54d3c)

  Thread T2 (tid=464095, running) created by main thread at:
    #0 pthread_create
/disk-samsung/freebsd-src/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1022:3
(a.out+0x264435)
    #1 __kmp_create_worker
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp:803:7
(libomp.so+0xca8d8)

SUMMARY: ThreadSanitizer: data race
/disk-samsung/freebsd-src/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp:1381:16
in __kmp_lock_suspend_mx
==================
[LWP 464095 of process 56986 exited]
[LWP 464094 of process 56986 exited]
[LWP 464096 of process 56986 exited]
ThreadSanitizer: reported 1 warnings
[LWP 464093 of process 56986 exited]
[Inferior 1 (process 56986) exited with code 0102]

-- 
You are receiving this mail because:
You are the assignee for the bug.