[libcxxabi] Cleanup memory in tests to placate ASAN.

Summary: ASAN fires on these tests because they don't clean up their memory.

Reviewers: danalbert, jroelofs, mclow.lists

Reviewed By: jroelofs

Subscribers: dblaikie, cfe-commits

Differential Revision: http://reviews.llvm.org/D6281

llvm-svn: 222493
This commit is contained in:
Eric Fiselier 2014-11-21 01:53:51 +00:00
parent 9ce6beaf07
commit a315865759
3 changed files with 15 additions and 12 deletions

View File

@ -135,9 +135,10 @@ struct vDerived : virtual public vBase {};
void test8 () void test8 ()
{ {
vDerived derived;
try try
{ {
throw new vDerived; throw &derived;
assert(false); assert(false);
} }
catch (vBase *p) { catch (vBase *p) {

View File

@ -56,11 +56,11 @@ void f2() {
} }
void f3() { void f3() {
Child* child = new Child; static Child child;
child->b1 = 10; child.b1 = 10;
child->b2 = 11; child.b2 = 11;
child->c = 12; child.c = 12;
throw static_cast<Base2*>(child); throw static_cast<Base2*>(&child);
} }
int main() int main()

View File

@ -11,6 +11,7 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <cassert>
// Wrapper routines // Wrapper routines
void *my_alloc2 ( size_t sz ) { void *my_alloc2 ( size_t sz ) {
@ -206,31 +207,32 @@ int test_exception_in_constructor ( ) {
int test_exception_in_destructor ( ) { int test_exception_in_destructor ( ) {
int retVal = 0; int retVal = 0;
void *one, *two, *three; void *one, *two, *three;
one = two = three = NULL;
// Throw from within a destructor // Throw from within a destructor
gConstructorCounter = gDestructorCounter = 0; gConstructorCounter = gDestructorCounter = 0;
gConstructorThrowTarget = -1; gConstructorThrowTarget = -1;
gDestructorThrowTarget = 15; gDestructorThrowTarget = 15;
try { try {
one = two = three = NULL; one = two = NULL;
one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct );
two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 );
three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 );
} }
catch ( int i ) {} catch ( int i ) {}
try { try {
__cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct );
__cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 );
__cxxabiv1::__cxa_vec_delete3( three, 40, 8, throw_destruct, my_dealloc3 ); assert(false);
} }
catch ( int i ) {} catch ( int i ) {}
// We should have thrown in the middle of cleaning up "two", which means that // We should have thrown in the middle of cleaning up "two", which means that
// there should be 20 calls to the destructor, and "three" was not cleaned up. // there should be 20 calls to the destructor and the try block should exit
if ( gConstructorCounter != 30 || gDestructorCounter != 20 ) { // before the assertion.
if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) {
std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl; std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl;
std::cerr << "Expected (30, 20), but got (" << gConstructorCounter << ", " << std::cerr << "Expected (20, 20), but got (" << gConstructorCounter << ", " <<
gDestructorCounter << ")" << std::endl; gDestructorCounter << ")" << std::endl;
retVal = 1; retVal = 1;
} }