[libc++] Rename *SAFE_STATIC to *CONSTINIT, and normalize its uses.

In src/, most files can use `constinit` directly because they're always
compiled with C++20. But some files, like "libcxxabi/src/fallback_malloc.cpp",
can't, because they're `#include`d directly from test cases in libcxxabi/test/
and therefore must (currently) compile as C++03. We might consider refactoring
those offending tests, or at least marking them `UNSUPPORTED: c++03`.

Differential Revision: https://reviews.llvm.org/D119264

NOKEYCHECK=True
GitOrigin-RevId: 05337a756c6606fdbf2c0ff3a8399da3e60f1591
diff --git a/src/debug.cpp b/src/debug.cpp
index ae31c91..15d8fdb 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -35,8 +35,7 @@
     std::abort();
 }
 
-_LIBCPP_SAFE_STATIC __libcpp_debug_function_type
-    __libcpp_debug_function = __libcpp_abort_debug_function;
+constinit __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function;
 
 bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) {
   __libcpp_debug_function = __func;
diff --git a/src/experimental/memory_resource.cpp b/src/experimental/memory_resource.cpp
index 018d015..af86079 100644
--- a/src/experimental/memory_resource.cpp
+++ b/src/experimental/memory_resource.cpp
@@ -97,7 +97,7 @@
 __default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
 {
 #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
-    _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
+    static constinit atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
     if (set) {
         new_res = new_res ? new_res : new_delete_resource();
         // TODO: Can a weaker ordering be used?
@@ -109,7 +109,7 @@
             &__res, memory_order_acquire);
     }
 #elif !defined(_LIBCPP_HAS_NO_THREADS)
-    _LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
+    static constinit memory_resource *res = &res_init.resources.new_delete_res;
     static mutex res_lock;
     if (set) {
         new_res = new_res ? new_res : new_delete_resource();
@@ -122,7 +122,7 @@
         return res;
     }
 #else
-    _LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
+    static constinit memory_resource *res = &res_init.resources.new_delete_res;
     if (set) {
         new_res = new_res ? new_res : new_delete_resource();
         memory_resource * old_res = res;
diff --git a/src/experimental/memory_resource_init_helper.h b/src/experimental/memory_resource_init_helper.h
index 56b9da6..032edc1 100644
--- a/src/experimental/memory_resource_init_helper.h
+++ b/src/experimental/memory_resource_init_helper.h
@@ -1,2 +1,2 @@
 #pragma GCC system_header
-_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
+static constinit ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
diff --git a/src/memory.cpp b/src/memory.cpp
index 4c9bf9f..e998e97 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -132,8 +132,8 @@
 
 #if !defined(_LIBCPP_HAS_NO_THREADS)
 
-_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
+static constexpr std::size_t __sp_mut_count = 16;
+static constinit __libcpp_mutex_t mut_back[__sp_mut_count] =
 {
     _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
     _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
@@ -171,8 +171,7 @@
 __sp_mut&
 __get_sp_mut(const void* p)
 {
-    static __sp_mut muts[__sp_mut_count]
-    {
+    static constinit __sp_mut muts[__sp_mut_count] = {
         &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
         &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
         &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
diff --git a/src/mutex.cpp b/src/mutex.cpp
index d6758fb..6669e76 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -196,8 +196,8 @@
 // keep in sync with:  7741191.
 
 #ifndef _LIBCPP_HAS_NO_THREADS
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
-_LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
+static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
+static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
 #endif
 
 void __call_once(volatile once_flag::_State_type& flag, void* arg,
diff --git a/src/random_shuffle.cpp b/src/random_shuffle.cpp
index df9b7d5..753a15f 100644
--- a/src/random_shuffle.cpp
+++ b/src/random_shuffle.cpp
@@ -18,7 +18,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifndef _LIBCPP_HAS_NO_THREADS
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
+static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
 #endif
 unsigned __rs_default::__c_ = 0;
 
diff --git a/src/support/runtime/exception_fallback.ipp b/src/support/runtime/exception_fallback.ipp
index 67ebde3..ade9335 100644
--- a/src/support/runtime/exception_fallback.ipp
+++ b/src/support/runtime/exception_fallback.ipp
@@ -11,9 +11,8 @@
 
 namespace std {
 
-_LIBCPP_SAFE_STATIC static std::terminate_handler  __terminate_handler;
-_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
-
+static constinit std::terminate_handler  __terminate_handler = nullptr;
+static constinit std::unexpected_handler __unexpected_handler = nullptr;
 
 // libcxxrt provides implementations of these functions itself.
 unexpected_handler
@@ -26,7 +25,6 @@
 get_unexpected() noexcept
 {
   return __libcpp_atomic_load(&__unexpected_handler);
-
 }
 
 _LIBCPP_NORETURN
diff --git a/src/support/runtime/new_handler_fallback.ipp b/src/support/runtime/new_handler_fallback.ipp
index a969b2a..2ec4083 100644
--- a/src/support/runtime/new_handler_fallback.ipp
+++ b/src/support/runtime/new_handler_fallback.ipp
@@ -9,7 +9,7 @@
 
 namespace std {
 
-_LIBCPP_SAFE_STATIC static std::new_handler __new_handler;
+static constinit std::new_handler __new_handler = nullptr;
 
 new_handler
 set_new_handler(new_handler handler) noexcept