| Issue |
53067
|
| Summary |
False thread-sanitizer positive when using OpenMP (archer) with C++11 thread-safe statics on macOS
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
q-p
|
I'm trying to apply thread-sanitizer (tsan) to an OpenMP parallelized C++11 program, and it seems like I get a race report which (AFAIK) isn't actually a real race on macOS 12 "Monterey".
This is using Homebrew clang 13
```
Homebrew clang version 13.0.0
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
```
on macOS 12.1 "Monterey" on an Intel Mac Pro (2019).
The following program
```cpp
#include <vector>
#include <iostream>
int main (int argc, char const *argv[])
{
#pragma omp parallel
{
static const std::vector<int> vec(1, 42);
std::cout << vec.size() << std::endl;
}
return 0;
}
```
compiled via `/usr/local/opt/llvm/bin/clang++ -L /usr/local/opt/llvm/lib -fopenmp -fsanitize=thread -std=c++11 omp_threadsafe_init_archer.cpp` (the `-L path` is given so the linking step picks up the OpenMP run-time library) and then run via
```
OMP_TOOL_LIBRARIES=~/Downloads/openmp-13.0.0.src/tools/archer/libarcher.dylib OMP_NUM_THREADS=2 MallocNanoZone=0 TSAN_OPTIONS="ignore_noninstrumented_modules=1" ./a.out
```
leads to the following output and TSAN report
```
1
==================
WARNING: ThreadSanitizer: data race (pid=51403)
Read of size 8 at 0x000109889138 by thread T1:
#0 std::__1::vector<int, std::__1::allocator<int> >::size() const <null> (a.out:x86_64+0x100001f4d)
#1 .omp_outlined. <null> (a.out:x86_64+0x100001ddc)
#2 __kmp_invoke_microtask <null> (libomp.dylib:x86_64+0x7a852)
#3 main <null> (a.out:x86_64+0x100001d03)
Previous write of size 8 at 0x000109889138 by main thread:
#0 std::__1::__vector_base<int, std::__1::allocator<int> >::__vector_base() <null> (a.out:x86_64+0x1000021ab)
#1 std::__1::vector<int, std::__1::allocator<int> >::vector(unsigned long, int const&) <null> (a.out:x86_64+0x1000020e1)
#2 std::__1::vector<int, std::__1::allocator<int> >::vector(unsigned long, int const&) <null> (a.out:x86_64+0x100001e95)
#3 .omp_outlined. <null> (a.out:x86_64+0x100001da5)
#4 __kmp_invoke_microtask <null> (libomp.dylib:x86_64+0x7a852)
#5 main <null> (a.out:x86_64+0x100001d03)
Location is global 'main::vec' of size 24 at 0x000109889130 (a.out+0x000100008138)
Thread T1 (tid=5238101, running) created by main thread at:
#0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:x86_64+0x9fdf)
#1 __kmp_create_worker <null> (libomp.dylib:x86_64+0x60daa)
```
>From what I understand (and have observed in real code) the C++11 static initialization is automatically thread-safe, so that the subsequent access from the 2nd thread should not race (the access from whichever thread initialized it must already have happened as the size is already printed).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs