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 | 89d7ff5de676464f33136778b1bf87ee945bf688 (patch) | |
| tree | 880d509d6b2e7209e4a20121ae3ea90b7888044f /compiler-rt/test | |
| parent | f6508db485936dd22bc0661d1f3eaf26e352c56d (diff) | |
| download | bcm5719-llvm-89d7ff5de676464f33136778b1bf87ee945bf688.tar.gz bcm5719-llvm-89d7ff5de676464f33136778b1bf87ee945bf688.zip | |
[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
llvm-svn: 253576
Diffstat (limited to 'compiler-rt/test')
| -rw-r--r-- | compiler-rt/test/lsan/TestCases/cleanup_in_tsd_destructor.c (renamed from compiler-rt/test/lsan/TestCases/cleanup_in_tsd_destructor.cc) | 2 | ||||
| -rw-r--r-- | compiler-rt/test/lsan/TestCases/disabler.c | 24 | ||||
| -rw-r--r-- | compiler-rt/test/lsan/TestCases/disabler.cc | 10 | ||||
| -rw-r--r-- | compiler-rt/test/lsan/TestCases/disabler_in_tsd_destructor.c (renamed from compiler-rt/test/lsan/TestCases/disabler_in_tsd_destructor.cc) | 5 | ||||
| -rw-r--r-- | compiler-rt/test/lsan/TestCases/ignore_object.c (renamed from compiler-rt/test/lsan/TestCases/ignore_object.cc) | 4 |
5 files changed, 36 insertions, 9 deletions
diff --git a/compiler-rt/test/lsan/TestCases/cleanup_in_tsd_destructor.cc b/compiler-rt/test/lsan/TestCases/cleanup_in_tsd_destructor.c index 5335454ffbe..debf05c2047 100644 --- a/compiler-rt/test/lsan/TestCases/cleanup_in_tsd_destructor.cc +++ b/compiler-rt/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/compiler-rt/test/lsan/TestCases/disabler.c b/compiler-rt/test/lsan/TestCases/disabler.c new file mode 100644 index 00000000000..1c4529df4f8 --- /dev/null +++ b/compiler-rt/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/compiler-rt/test/lsan/TestCases/disabler.cc b/compiler-rt/test/lsan/TestCases/disabler.cc index f83106501fa..12e5ffe4d44 100644 --- a/compiler-rt/test/lsan/TestCases/disabler.cc +++ b/compiler-rt/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/compiler-rt/test/lsan/TestCases/disabler_in_tsd_destructor.cc b/compiler-rt/test/lsan/TestCases/disabler_in_tsd_destructor.c index a0012c74dd9..982fb899ec5 100644 --- a/compiler-rt/test/lsan/TestCases/disabler_in_tsd_destructor.cc +++ b/compiler-rt/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/compiler-rt/test/lsan/TestCases/ignore_object.cc b/compiler-rt/test/lsan/TestCases/ignore_object.c index ac69e12a4ba..2aa4f14e291 100644 --- a/compiler-rt/test/lsan/TestCases/ignore_object.cc +++ b/compiler-rt/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. |

