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: %clang_lsan %s -o %t
7 // RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=1" %run %t
8 // RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
10 // Investigate why it does not fail with use_stack=0
11 // UNSUPPORTED: arm-linux || armhf-linux
18 #include "sanitizer/lsan_interface.h"
19 #include "sanitizer_common/print_address.h"
24 void key_destructor(void *arg
) {
25 // Generally this may happen on a different thread.
26 __lsan_do_leak_check();
29 void *thread_func(void *arg
) {
31 print_address("Test alloc: ", 1, p
);
32 int res
= pthread_setspecific(key
, (void*)1);
38 int res
= pthread_key_create(&key
, &key_destructor
);
41 res
= pthread_create(&thread_id
, 0, thread_func
, 0);
43 res
= pthread_join(thread_id
, 0);
47 // CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
48 // CHECK: [[ADDR]] (1337 bytes)