1// Test that TLS is unpoisoned on thread death.
2// REQUIRES: x86-target-arch && !android
3
4// RUN: %clangxx_asan -O0 %s -pthread -o %t && %run %t 2>&1
5// RUN: %clangxx_asan -O1 %s -pthread -o %t && %run %t 2>&1
6
7#include <assert.h>
8#include <pthread.h>
9#include <stdio.h>
10
11#include <sanitizer/asan_interface.h>
12
13__thread int64_t tls_var[2];
14
15volatile int64_t *p_tls_var;
16
17void *first(void *arg) {
18 ASAN_POISON_MEMORY_REGION(&tls_var, sizeof(tls_var));
19 p_tls_var = tls_var;
20 return 0;
21}
22
23void *second(void *arg) {
24 assert(tls_var == p_tls_var);
25 *p_tls_var = 1;
26 return 0;
27}
28
29int main(int argc, char *argv[]) {
30 pthread_t p;
31 assert(0 == pthread_create(&p, 0, first, 0));
32 assert(0 == pthread_join(p, 0));
33 assert(0 == pthread_create(&p, 0, second, 0));
34 assert(0 == pthread_join(p, 0));
35 return 0;
36}
37

source code of compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp