[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
This commit is contained in:
Alexey Samsonov 2015-11-19 17:18:02 +00:00
parent f6508db485
commit 89d7ff5de6
5 changed files with 36 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -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]]

View File

@ -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) {

View File

@ -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.