2 changes: 2 additions & 0 deletions libcxxabi/test/catch_ptr_02.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <cassert>

#if __cplusplus < 201103L
Expand Down
55 changes: 55 additions & 0 deletions libcxxabi/test/cxa_bad_cast.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===----------------------- cxa_bad_cast.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03

#include <cxxabi.h>
#include <cassert>
#include <stdlib.h>
#include <exception>
#include <typeinfo>

class Base {
virtual void foo() {};
};

class Derived : public Base {};

Derived &test_bad_cast(Base b) {
return dynamic_cast<Derived&>(b);
}

Base gB;

void my_terminate() { exit(0); }

int main ()
{
// swap-out the terminate handler
void (*default_handler)() = std::get_terminate();
std::set_terminate(my_terminate);

#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
try {
#endif
Derived &d = test_bad_cast(gB);
assert(false);
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
} catch (std::bad_cast) {
// success
return 0;
} catch (...) {
assert(false);
}
#endif

// failure, restore the default terminate handler and fire
std::set_terminate(default_handler);
std::terminate();
}
55 changes: 55 additions & 0 deletions libcxxabi/test/cxa_bad_typeid.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===----------------------- cxa_bad_typeid.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===------------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03

#include <cxxabi.h>
#include <cassert>
#include <stdlib.h>
#include <exception>
#include <typeinfo>
#include <string>
#include <iostream>

class Base {
virtual void foo() {};
};

class Derived : public Base {};

std::string test_bad_typeid(Derived *p) {
typeid(*p).name();
}

void my_terminate() { std::cout << "A" << std::endl; exit(0); }

int main ()
{
// swap-out the terminate handler
void (*default_handler)() = std::get_terminate();
std::set_terminate(my_terminate);

#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
try {
#endif
test_bad_typeid(nullptr);
assert(false);
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
} catch (std::bad_typeid) {
// success
return 0;
} catch (...) {
assert(false);
}
#endif

// failure, restore the default terminate handler and fire
std::set_terminate(default_handler);
std::terminate();
}
2 changes: 2 additions & 0 deletions libcxxabi/test/incomplete_type.sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// incomplete flags set, equality can be tested by comparing the type_info
// addresses.

// UNSUPPORTED: libcxxabi-no-exceptions

// RUN: %cxx %flags %compile_flags -c %s -o %t.one.o
// RUN: %cxx %flags %compile_flags -c %s -o %t.two.o -DTU_ONE
// RUN: %cxx %flags %t.one.o %t.two.o %link_flags -o %t.exe
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/inherited_exception.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <assert.h>

struct Base {
Expand Down
7 changes: 6 additions & 1 deletion libcxxabi/test/libcxxabi/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ def configure_obj_root(self):

def configure_features(self):
super(Configuration, self).configure_features()
if not self.get_lit_bool('enable_exceptions', True):
self.config.available_features.add('libcxxabi-no-exceptions')
if self.get_lit_bool('thread_atexit', True):
self.config.available_features.add('thread_atexit')

def configure_compile_flags(self):
self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
self.cxx.compile_flags += ['-funwind-tables']
if self.get_lit_bool('enable_exceptions', True):
self.cxx.compile_flags += ['-funwind-tables']
else:
self.cxx.compile_flags += ['-fno-exceptions', '-DLIBCXXABI_HAS_NO_EXCEPTIONS']
if not self.get_lit_bool('enable_threads', True):
self.cxx.compile_flags += ['-DLIBCXXABI_HAS_NO_THREADS=1']
super(Configuration, self).configure_compile_flags()
Expand Down
1 change: 1 addition & 0 deletions libcxxabi/test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ config.executor = "@LIBCXXABI_EXECUTOR@"
config.thread_atexit = "@LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL@"
config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
config.enable_shared = "@LIBCXX_ENABLE_SHARED@"
config.enable_exceptions = "@LIBCXXABI_ENABLE_EXCEPTIONS@"

# Let the main config do the real work.
lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")
38 changes: 38 additions & 0 deletions libcxxabi/test/noexception1.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------- noexception1.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03
// REQUIRES: libcxxabi-no-exceptions

#include <cxxabi.h>
#include <exception>
#include <cassert>
#include <stdlib.h>

// namespace __cxxabiv1 {
// void __cxa_increment_exception_refcount(void *thrown_object) throw();
// }

unsigned gCounter = 0;

void my_terminate() { exit(0); }

int main ()
{
// should not call std::terminate()
__cxxabiv1::__cxa_increment_exception_refcount(nullptr);

std::set_terminate(my_terminate);

// should call std::terminate()
__cxxabiv1::__cxa_increment_exception_refcount((void*) &gCounter);
assert(false);

return 0;
}
38 changes: 38 additions & 0 deletions libcxxabi/test/noexception2.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------- noexception2.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03
// REQUIRES: libcxxabi-no-exceptions

#include <cxxabi.h>
#include <exception>
#include <cassert>
#include <stdlib.h>

// namespace __cxxabiv1 {
// void __cxa_decrement_exception_refcount(void *thrown_object) throw();
// }

unsigned gCounter = 0;

void my_terminate() { exit(0); }

int main ()
{
// should not call std::terminate()
__cxxabiv1::__cxa_decrement_exception_refcount(nullptr);

std::set_terminate(my_terminate);

// should call std::terminate()
__cxxabiv1::__cxa_decrement_exception_refcount((void*) &gCounter);
assert(false);

return 0;
}
38 changes: 38 additions & 0 deletions libcxxabi/test/noexception3.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------- noexception3.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03
// REQUIRES: libcxxabi-no-exceptions

#include <cxxabi.h>
#include <exception>
#include <cassert>
#include <stdlib.h>

// namespace __cxxabiv1 {
// void __cxa_rethrow_primary_exception(void* thrown_object);
// }

unsigned gCounter = 0;

void my_terminate() { exit(0); }

int main ()
{
// should not call std::terminate()
__cxxabiv1::__cxa_rethrow_primary_exception(nullptr);

std::set_terminate(my_terminate);

// should call std::terminate()
__cxxabiv1::__cxa_rethrow_primary_exception((void*) &gCounter);
assert(false);

return 0;
}
29 changes: 29 additions & 0 deletions libcxxabi/test/noexception4.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===----------------------- noexception4.pass.cpp ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// REQUIRES: libcxxabi-no-exceptions

#include <cxxabi.h>
#include <exception>
#include <cassert>

// namespace __cxxabiv1 {
// void *__cxa_current_primary_exception() throw();
// extern bool __cxa_uncaught_exception () throw();
// extern unsigned int __cxa_uncaught_exceptions() throw();
// }

int main ()
{
// Trivially
assert(nullptr == __cxxabiv1::__cxa_current_primary_exception());
assert(!__cxxabiv1::__cxa_uncaught_exception());
assert(0 == __cxxabiv1::__cxa_uncaught_exceptions());
return 0;
}
2 changes: 2 additions & 0 deletions libcxxabi/test/test_aux_runtime.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <typeinfo>
#include <iostream>

Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <iostream>
#include <cxxabi.h>

Expand Down
4 changes: 4 additions & 0 deletions libcxxabi/test/test_guard.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace test1 {
// When initialization fails, ensure that we try to initialize it again next
// time.
namespace test2 {
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
static int run_count = 0;
int increment() {
++run_count;
Expand All @@ -58,6 +59,9 @@ namespace test2 {
helper();
assert(run_count == 2);
}
#else
void test() {}
#endif
}

// Check that we can initialize a second value while initializing a first.
Expand Down
21 changes: 19 additions & 2 deletions libcxxabi/test/test_vector1.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ int gConstructorCounter;
int gConstructorThrowTarget;
int gDestructorCounter;
int gDestructorThrowTarget;
void throw_construct ( void *p ) { if ( gConstructorCounter == gConstructorThrowTarget ) throw 1; ++gConstructorCounter; }
void throw_destruct ( void *p ) { if ( ++gDestructorCounter == gDestructorThrowTarget ) throw 2; }
void throw_construct ( void *p ) {
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
if ( gConstructorCounter == gConstructorThrowTarget )
throw 1;
++gConstructorCounter;
#endif
}
void throw_destruct ( void *p ) {
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
if ( ++gDestructorCounter == gDestructorThrowTarget )
throw 2;
#endif
}

#if __cplusplus >= 201103L
# define CAN_THROW noexcept(false)
Expand Down Expand Up @@ -146,6 +157,7 @@ int test_counted ( ) {
return retVal;
}

#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
// Make sure the constructors and destructors are matched
int test_exception_in_constructor ( ) {
int retVal = 0;
Expand Down Expand Up @@ -202,7 +214,9 @@ int test_exception_in_constructor ( ) {

return retVal;
}
#endif

#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
// Make sure the constructors and destructors are matched
int test_exception_in_destructor ( ) {
int retVal = 0;
Expand Down Expand Up @@ -253,12 +267,15 @@ int test_exception_in_destructor ( ) {

return retVal;
}
#endif

int main ( int argc, char *argv [] ) {
int retVal = 0;
retVal += test_empty ();
retVal += test_counted ();
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
retVal += test_exception_in_constructor ();
retVal += test_exception_in_destructor ();
#endif
return retVal;
}
2 changes: 2 additions & 0 deletions libcxxabi/test/test_vector2.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include "cxxabi.h"

#include <iostream>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/test_vector3.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include "cxxabi.h"

#include <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/uncaught_exceptions.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <cxxabi.h>
#include <exception>
#include <cassert>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_01.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <assert.h>

struct A
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_02.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <assert.h>

struct A
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_03.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <exception>
#include <stdlib.h>
#include <assert.h>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_04.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <exception>
#include <stdlib.h>
#include <assert.h>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_05.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <exception>
#include <stdlib.h>
#include <assert.h>
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/unwind_06.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxxabi-no-exceptions

#include <exception>
#include <stdlib.h>
#include <assert.h>
Expand Down