1 // Regression test for thread lifetime tracking. Thread data should be
2 // considered live during the thread's termination, at least until the
3 // user-installed TSD destructors have finished running (since they may contain
4 // additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it
5 // makes its best effort.
6 // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0"
7 // RUN: %clang_lsan %s -o %t
8 // RUN: %env_lsan_opts=$LSAN_BASE:use_tls=1 %run %t
9 // RUN: %env_lsan_opts=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s
16 #include "sanitizer/lsan_interface.h"
17 #include "sanitizer_common/print_address.h"
22 void key_destructor(void *arg) {
23 // Generally this may happen on a different thread.
24 __lsan_do_leak_check();
27 void *thread_func(void *arg) {
29 print_address("Test alloc: ", 1, p);
30 int res = pthread_setspecific(key, (void*)1);
36 int res = pthread_key_create(&key, &key_destructor);
39 res = pthread_create(&thread_id, 0, thread_func, 0);
41 res = pthread_join(thread_id, 0);
45 // CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
46 // CHECK: [[ADDR]] (1337 bytes)