1// RUN: %clangxx_msan -O0 %s -o %t && %run %t
2
3// Check that when TLS block is reused between threads, its shadow is cleaned.
4
5#include <pthread.h>
6#include <stdio.h>
7
8int __thread x;
9
10void *ThreadFn(void *) {
11 if (!x)
12 printf(format: "zzz\n");
13 int y;
14 int * volatile p = &y;
15 x = *p;
16 return 0;
17}
18
19int main(void) {
20 pthread_t t;
21 for (int i = 0; i < 100; ++i) {
22 pthread_create(newthread: &t, attr: 0, start_routine: ThreadFn, arg: 0);
23 pthread_join(th: t, thread_return: 0);
24 }
25 return 0;
26}
27

source code of compiler-rt/test/msan/tls_reuse.cpp