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>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False thread-sanitizer positive when using OpenMP (archer) with C++11 thread-safe statics on macOS
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
q-p
</td>
</tr>
</table>
<pre>
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).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV1uP6jYQ_jXhxSJKHK4PPLDL0oO6N-1SVepL5CQG3DV2ajuw9Nd3xgmBXZDO9rSViqKQZMYz428unsl0cZgsAjrcEmcOQq2J04SVpTwQtzGcFV3LlHDiT25IQEcO3gI69kyKPJVcPTyTkhkmJZfAVJDbgN7AFcekNHpt2Dagt8BbEOGI5XxriRRvnCzImjvCiGE5J4aX2jiy34h8g1qm8-niZ1QjLGgbAl_uKlBxwAWcyXqVVmTL8qdXElNYRB-0ctzwAzyGQTQLoml9X26EBUGksri7b3rLM8P3JJcMXuOkYR1EzeVfP3HtuLEC1MVJGIUNy5IZ2EGQTMn7aJAOel0EjXcLZvZC0TikLaOHkWx1wSWyl9qK95q0UNYhcsVMGCQFdF5ZA3epcybhX5cO3-QOUJxnQl01tr6foRHGn_BAqMBdC_ggyQPLybPRiDON4jHA_AGuo9GcrLSUeo-gHT35UXtels0XmgiVy6rgJEhudzx3GrZzd40otHUAx_ZE9nehHFgvFBqFz4BtjnGTb5ghuQaYgDKFr7ugfxP0Z2B0s3x4Uz8QYEhKw9ZbRvS2bGOypZ4YCQHUnc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