diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-11-19 17:18:02 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-11-19 17:18:02 +0000 |
commit | 653078b1212eb5f696fcb92d27f4ae1202a373d6 (patch) | |
tree | 08a3153f6df58c72513b410a42d0607f89a3e329 /test/lsan/TestCases | |
parent | 09e0defb19924e9a36b0a5380b50690f179d2e14 (diff) |
[LSan] Fix tests with some libstdc++ implementations.
Summary:
Newer libstdc++ has global pool, which is filled with objects
allocated during libstdc++ initialization, and never released.
Using use_globals=0 in the lit tests results in these objects
being treated as leaks.
Fix this by porting several tests to plain C, and introducing
a simple sanity test case for __lsan::ScopedDisabler.
Reviewers: kcc, ygribov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D14798
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@253576 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/lsan/TestCases')
-rw-r--r-- | test/lsan/TestCases/cleanup_in_tsd_destructor.c (renamed from test/lsan/TestCases/cleanup_in_tsd_destructor.cc) | 2 | ||||
-rw-r--r-- | test/lsan/TestCases/disabler.c | 24 | ||||
-rw-r--r-- | test/lsan/TestCases/disabler.cc | 10 | ||||
-rw-r--r-- | test/lsan/TestCases/disabler_in_tsd_destructor.c (renamed from test/lsan/TestCases/disabler_in_tsd_destructor.cc) | 5 | ||||
-rw-r--r-- | test/lsan/TestCases/ignore_object.c (renamed from test/lsan/TestCases/ignore_object.cc) | 4 |
5 files changed, 36 insertions, 9 deletions
diff --git a/test/lsan/TestCases/cleanup_in_tsd_destructor.cc b/test/lsan/TestCases/cleanup_in_tsd_destructor.c index 5335454ff..debf05c20 100644 --- a/test/lsan/TestCases/cleanup_in_tsd_destructor.cc +++ b/test/lsan/TestCases/cleanup_in_tsd_destructor.c @@ -4,7 +4,7 @@ // 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: %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 diff --git a/test/lsan/TestCases/disabler.c b/test/lsan/TestCases/disabler.c new file mode 100644 index 000000000..1c4529df4 --- /dev/null +++ b/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 <stdio.h> +#include <stdlib.h> + +#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) diff --git a/test/lsan/TestCases/disabler.cc b/test/lsan/TestCases/disabler.cc index f83106501..12e5ffe4d 100644 --- a/test/lsan/TestCases/disabler.cc +++ b/test/lsan/TestCases/disabler.cc @@ -13,11 +13,13 @@ int main() { { __lsan::ScopedDisabler d; p = new void *; + fprintf(stderr, "Test alloc p: %p.\n", p); } - *reinterpret_cast<void **>(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]] diff --git a/test/lsan/TestCases/disabler_in_tsd_destructor.cc b/test/lsan/TestCases/disabler_in_tsd_destructor.c index a0012c74d..982fb899e 100644 --- a/test/lsan/TestCases/disabler_in_tsd_destructor.cc +++ b/test/lsan/TestCases/disabler_in_tsd_destructor.c @@ -1,6 +1,6 @@ // 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: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t #include <assert.h> @@ -13,11 +13,12 @@ pthread_key_t key; void key_destructor(void *arg) { - __lsan::ScopedDisabler d; + __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) { diff --git a/test/lsan/TestCases/ignore_object.cc b/test/lsan/TestCases/ignore_object.c index ac69e12a4..2aa4f14e2 100644 --- a/test/lsan/TestCases/ignore_object.cc +++ b/test/lsan/TestCases/ignore_object.c @@ -1,6 +1,6 @@ // 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: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s #include <stdio.h> @@ -10,7 +10,7 @@ int main() { // Explicitly ignored object. - void **p = new void *; + void **p = malloc(sizeof(void *)); // Transitively ignored object. *p = malloc(666); // Non-ignored object. |