[libc++abi] Replace LIBCXXABI_HAS_NO_EXCEPTIONS by TEST_HAS_NO_EXCEPTIONS

This clarifies the difference between test for exception support in
libc++abi tests and support for exceptions built into libc++abi.
This also removes the rather confusing similarity between the
_LIBCXXABI_NO_EXCEPTIONS and LIBCXXABI_HAS_NO_EXCEPTIONS macros.

Finally, TEST_HAS_NO_EXCEPTIONS is also detected automatically based
on -fno-exceptions, so it doesn't have to be specified explicitly
through Lit's compile_flags.

GitOrigin-RevId: e6d94f4bd210f01a6dedf3cdd9ac331815cc7874
diff --git a/test/cxa_bad_cast.pass.cpp b/test/cxa_bad_cast.pass.cpp
index c6fb8ee..5ff64e8 100644
--- a/test/cxa_bad_cast.pass.cpp
+++ b/test/cxa_bad_cast.pass.cpp
@@ -14,6 +14,8 @@
 #include <exception>
 #include <typeinfo>
 
+#include "test_macros.h"
+
 class Base {
   virtual void foo() {};
 };
@@ -34,13 +36,13 @@
     void (*default_handler)() = std::get_terminate();
     std::set_terminate(my_terminate);
 
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     try {
 #endif
         Derived &d = test_bad_cast(gB);
         assert(false);
         ((void)d);
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     } catch (std::bad_cast) {
         // success
         return 0;
diff --git a/test/cxa_bad_typeid.pass.cpp b/test/cxa_bad_typeid.pass.cpp
index 116f98f..fc491d7 100644
--- a/test/cxa_bad_typeid.pass.cpp
+++ b/test/cxa_bad_typeid.pass.cpp
@@ -16,6 +16,8 @@
 #include <string>
 #include <iostream>
 
+#include "test_macros.h"
+
 class Base {
   virtual void foo() {};
 };
@@ -34,12 +36,12 @@
     void (*default_handler)() = std::get_terminate();
     std::set_terminate(my_terminate);
 
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     try {
 #endif
         test_bad_typeid(nullptr);
         assert(false);
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     } catch (std::bad_typeid) {
         // success
         return 0;
diff --git a/test/guard_threaded_test.pass.cpp b/test/guard_threaded_test.pass.cpp
index 43636c5..0dc911c 100644
--- a/test/guard_threaded_test.pass.cpp
+++ b/test/guard_threaded_test.pass.cpp
@@ -20,6 +20,8 @@
 #include <memory>
 #include <vector>
 
+#include "test_macros.h"
+
 
 using namespace __cxxabiv1;
 
@@ -88,13 +90,13 @@
   if (std::__libcpp_atomic_load(first_byte, std::_AO_Acquire) == 0) {
     Impl impl(g);
     if (impl.cxa_guard_acquire() == INIT_IS_PENDING) {
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
       try {
 #endif
         init();
         impl.cxa_guard_release();
         return PERFORMED;
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
       } catch (...) {
         impl.cxa_guard_abort();
         return ABORTED;
diff --git a/test/libcxxabi/test/config.py b/test/libcxxabi/test/config.py
index 37938d5..b9b2b6e 100644
--- a/test/libcxxabi/test/config.py
+++ b/test/libcxxabi/test/config.py
@@ -50,8 +50,6 @@
         ]
         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 += ['-D_LIBCXXABI_HAS_NO_THREADS']
             self.config.available_features.add('libcxxabi-no-threads')
diff --git a/test/test_guard.pass.cpp b/test/test_guard.pass.cpp
index 73f3559..8c96ae8 100644
--- a/test/test_guard.pass.cpp
+++ b/test/test_guard.pass.cpp
@@ -14,6 +14,8 @@
 #include <thread>
 #endif
 
+#include "test_macros.h"
+
 // Ensure that we initialize each variable once and only once.
 namespace test1 {
     static int run_count = 0;
@@ -40,7 +42,7 @@
 // When initialization fails, ensure that we try to initialize it again next
 // time.
 namespace test2 {
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     static int run_count = 0;
     int increment() {
         ++run_count;
diff --git a/test/test_vector1.pass.cpp b/test/test_vector1.pass.cpp
index 841d1ab..10b77b0 100644
--- a/test/test_vector1.pass.cpp
+++ b/test/test_vector1.pass.cpp
@@ -12,6 +12,8 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "test_macros.h"
+
 //  Wrapper routines
 void *my_alloc2 ( size_t sz ) {
     void *p = std::malloc ( sz );
@@ -47,14 +49,14 @@
 int gDestructorCounter;
 int gDestructorThrowTarget;
 void throw_construct ( void * ) {
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     if ( gConstructorCounter   == gConstructorThrowTarget )
         throw 1;
     ++gConstructorCounter;
 #endif
 }
 void throw_destruct  ( void * ) {
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     if ( ++gDestructorCounter  == gDestructorThrowTarget  )
         throw 2;
 #endif
@@ -156,7 +158,7 @@
     return retVal;
     }
     
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
 //  Make sure the constructors and destructors are matched
 int test_exception_in_constructor ( ) {
     int retVal = 0;
@@ -215,7 +217,7 @@
     }
 #endif
 
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
 //  Make sure the constructors and destructors are matched
 int test_exception_in_destructor ( ) {
     int retVal = 0;
@@ -272,7 +274,7 @@
     int retVal = 0;
     retVal += test_empty ();
     retVal += test_counted ();
-#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
+#ifndef TEST_HAS_NO_EXCEPTIONS
     retVal += test_exception_in_constructor ();
     retVal += test_exception_in_destructor ();
 #endif