Index: compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c +++ compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.c @@ -0,0 +1,45 @@ +// Regression test for thread lifetime tracking. Thread data should be +// considered live during the thread's termination, at least until the +// user-installed TSD destructors have finished running (since they may contain +// additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it +// makes its best effort. +// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0" +// RUN: %clang_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %run %t +// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s + +#include +#include +#include +#include + +#include "sanitizer/lsan_interface.h" + +pthread_key_t key; +__thread void *p; + +void key_destructor(void *arg) { + // Generally this may happen on a different thread. + __lsan_do_leak_check(); +} + +void *thread_func(void *arg) { + p = malloc(1337); + fprintf(stderr, "Test alloc: %p.\n", p); + int res = pthread_setspecific(key, (void*)1); + assert(res == 0); + return 0; +} + +int main() { + int res = pthread_key_create(&key, &key_destructor); + assert(res == 0); + pthread_t thread_id; + res = pthread_create(&thread_id, 0, thread_func, 0); + assert(res == 0); + res = pthread_join(thread_id, 0); + assert(res == 0); + return 0; +} +// CHECK: Test alloc: [[ADDR:.*]]. +// CHECK: [[ADDR]] (1337 bytes) Index: compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc +++ compiler-rt/trunk/test/lsan/TestCases/cleanup_in_tsd_destructor.cc @@ -1,45 +0,0 @@ -// Regression test for thread lifetime tracking. Thread data should be -// considered live during the thread's termination, at least until the -// user-installed TSD destructors have finished running (since they may contain -// additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it -// makes its best effort. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %run %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s - -#include -#include -#include -#include - -#include "sanitizer/lsan_interface.h" - -pthread_key_t key; -__thread void *p; - -void key_destructor(void *arg) { - // Generally this may happen on a different thread. - __lsan_do_leak_check(); -} - -void *thread_func(void *arg) { - p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - int res = pthread_setspecific(key, (void*)1); - assert(res == 0); - return 0; -} - -int main() { - int res = pthread_key_create(&key, &key_destructor); - assert(res == 0); - pthread_t thread_id; - res = pthread_create(&thread_id, 0, thread_func, 0); - assert(res == 0); - res = pthread_join(thread_id, 0); - assert(res == 0); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: [[ADDR]] (1337 bytes) Index: compiler-rt/trunk/test/lsan/TestCases/disabler.c =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/disabler.c +++ compiler-rt/trunk/test/lsan/TestCases/disabler.c @@ -0,0 +1,24 @@ +// Test for __lsan_disable() / __lsan_enable(). +// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" +// RUN: %clang_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s + +#include +#include + +#include "sanitizer/lsan_interface.h" + +int main() { + void **p; + { + __lsan_disable(); + p = malloc(sizeof(void *)); + __lsan_enable(); + } + *p = malloc(666); + void *q = malloc(1337); + // Break optimization. + fprintf(stderr, "Test alloc: %p.\n", q); + return 0; +} +// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) Index: compiler-rt/trunk/test/lsan/TestCases/disabler.cc =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/disabler.cc +++ compiler-rt/trunk/test/lsan/TestCases/disabler.cc @@ -13,11 +13,13 @@ { __lsan::ScopedDisabler d; p = new void *; + fprintf(stderr, "Test alloc p: %p.\n", p); } - *reinterpret_cast(p) = malloc(666); + *p = malloc(666); void *q = malloc(1337); - // Break optimization. - fprintf(stderr, "Test alloc: %p.\n", q); + fprintf(stderr, "Test alloc q: %p.\n", q); return 0; } -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) + +// CHECK: Test alloc p: [[ADDR:.*]]. +// CHECK-NOT: [[ADDR]] Index: compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c +++ compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.c @@ -0,0 +1,39 @@ +// Regression test. Disabler should not depend on TSD validity. +// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1" +// RUN: %clang_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t + +#include +#include +#include +#include + +#include "sanitizer/lsan_interface.h" + +pthread_key_t key; + +void key_destructor(void *arg) { + __lsan_disable(); + void *p = malloc(1337); + // Break optimization. + fprintf(stderr, "Test alloc: %p.\n", p); + pthread_setspecific(key, 0); + __lsan_enable(); +} + +void *thread_func(void *arg) { + int res = pthread_setspecific(key, (void*)1); + assert(res == 0); + return 0; +} + +int main() { + int res = pthread_key_create(&key, &key_destructor); + assert(res == 0); + pthread_t thread_id; + res = pthread_create(&thread_id, 0, thread_func, 0); + assert(res == 0); + res = pthread_join(thread_id, 0); + assert(res == 0); + return 0; +} Index: compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc +++ compiler-rt/trunk/test/lsan/TestCases/disabler_in_tsd_destructor.cc @@ -1,38 +0,0 @@ -// Regression test. Disabler should not depend on TSD validity. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t - -#include -#include -#include -#include - -#include "sanitizer/lsan_interface.h" - -pthread_key_t key; - -void key_destructor(void *arg) { - __lsan::ScopedDisabler d; - void *p = malloc(1337); - // Break optimization. - fprintf(stderr, "Test alloc: %p.\n", p); - pthread_setspecific(key, 0); -} - -void *thread_func(void *arg) { - int res = pthread_setspecific(key, (void*)1); - assert(res == 0); - return 0; -} - -int main() { - int res = pthread_key_create(&key, &key_destructor); - assert(res == 0); - pthread_t thread_id; - res = pthread_create(&thread_id, 0, thread_func, 0); - assert(res == 0); - res = pthread_join(thread_id, 0); - assert(res == 0); - return 0; -} Index: compiler-rt/trunk/test/lsan/TestCases/ignore_object.c =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/ignore_object.c +++ compiler-rt/trunk/test/lsan/TestCases/ignore_object.c @@ -0,0 +1,23 @@ +// Test for __lsan_ignore_object(). +// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" +// RUN: %clang_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s + +#include +#include + +#include "sanitizer/lsan_interface.h" + +int main() { + // Explicitly ignored object. + void **p = malloc(sizeof(void *)); + // Transitively ignored object. + *p = malloc(666); + // Non-ignored object. + volatile void *q = malloc(1337); + fprintf(stderr, "Test alloc: %p.\n", p); + __lsan_ignore_object(p); + return 0; +} +// CHECK: Test alloc: [[ADDR:.*]]. +// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) Index: compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc =================================================================== --- compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc +++ compiler-rt/trunk/test/lsan/TestCases/ignore_object.cc @@ -1,23 +0,0 @@ -// Test for __lsan_ignore_object(). -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s - -#include -#include - -#include "sanitizer/lsan_interface.h" - -int main() { - // Explicitly ignored object. - void **p = new void *; - // Transitively ignored object. - *p = malloc(666); - // Non-ignored object. - volatile void *q = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - __lsan_ignore_object(p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)