1/// The static TLS block is reused among by threads. The shadow is cleared.
2// RUN: %clang_nsan %s -o %t
3// RUN: env NSAN_OPTIONS=halt_on_error=1,log2_max_relative_error=19 %run %t
4
5#include <pthread.h>
6#include <stdio.h>
7
8__thread float x;
9
10static void *ThreadFn(void *a) {
11 long i = (long)a;
12 for (long j = i * 1000; j < (i + 1) * 1000; j++)
13 x += j;
14 printf(format: "%f\n", x);
15 return 0;
16}
17
18int main() {
19 pthread_t t;
20 for (long i = 0; i < 5; ++i) {
21 pthread_create(newthread: &t, attr: 0, start_routine: ThreadFn, arg: (void *)i);
22 pthread_join(th: t, thread_return: 0);
23 }
24}
25

source code of compiler-rt/test/nsan/Posix/tls_reuse.c