Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / unpoison_tls.cpp
blob8b405ac5f8651355402676784eb2fdb00810ec6f
1 // Test that TLS is unpoisoned on thread death.
2 // REQUIRES: x86-target-arch && !android
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
7 #include <assert.h>
8 #include <pthread.h>
9 #include <stdio.h>
11 #include <sanitizer/asan_interface.h>
13 __thread int64_t tls_var[2];
15 volatile int64_t *p_tls_var;
17 void *first(void *arg) {
18 ASAN_POISON_MEMORY_REGION(&tls_var, sizeof(tls_var));
19 p_tls_var = tls_var;
20 return 0;
23 void *second(void *arg) {
24 assert(tls_var == p_tls_var);
25 *p_tls_var = 1;
26 return 0;
29 int 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;