[libc++] Move everything related solely to _LIBCPP_ASSERT to its own file

This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.

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

NOKEYCHECK=True
GitOrigin-RevId: f87aa19be64499308fc18f92d048c5fa2d3064d9
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 12dcdf9..3395003 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -65,6 +65,7 @@
 
 if (LIBCXX_ENABLE_DEBUG_MODE_SUPPORT)
   list(APPEND LIBCXX_SOURCES
+    assert.cpp
     debug.cpp
     )
 endif()
diff --git a/src/assert.cpp b/src/assert.cpp
new file mode 100644
index 0000000..40c51f8
--- /dev/null
+++ b/src/assert.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <__assert>
+#include <__config>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+std::string __libcpp_debug_info::what() const {
+  string msg = __file_;
+  msg += ":" + std::to_string(__line_) + ": _LIBCPP_ASSERT '";
+  msg += __pred_;
+  msg += "' failed. ";
+  msg += __msg_;
+  return msg;
+}
+
+_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) {
+    std::fprintf(stderr, "%s\n", info.what().c_str());
+    std::abort();
+}
+
+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;
+  return true;
+}
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/src/debug.cpp b/src/debug.cpp
index 14a75b1..8f1d328 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__config>
 #include <__debug>
 #include <__hash_table>
@@ -23,26 +24,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-std::string __libcpp_debug_info::what() const {
-  string msg = __file_;
-  msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '";
-  msg += __pred_;
-  msg += "' failed. ";
-  msg += __msg_;
-  return msg;
-}
-_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) {
-    std::fprintf(stderr, "%s\n", info.what().c_str());
-    std::abort();
-}
-
-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;
-  return true;
-}
-
 _LIBCPP_FUNC_VIS
 __libcpp_db*
 __get_db()
diff --git a/src/filesystem/directory_iterator.cpp b/src/filesystem/directory_iterator.cpp
index c9294f7..8b91929 100644
--- a/src/filesystem/directory_iterator.cpp
+++ b/src/filesystem/directory_iterator.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__config>
 #include <errno.h>
 #include <filesystem>
diff --git a/src/filesystem/filesystem_common.h b/src/filesystem/filesystem_common.h
index 9415356..c98d144 100644
--- a/src/filesystem/filesystem_common.h
+++ b/src/filesystem/filesystem_common.h
@@ -9,6 +9,7 @@
 #ifndef FILESYSTEM_COMMON_H
 #define FILESYSTEM_COMMON_H
 
+#include <__assert>
 #include <__config>
 #include <array>
 #include <chrono>
diff --git a/src/filesystem/operations.cpp b/src/filesystem/operations.cpp
index 57e2539..0e2ebdf 100644
--- a/src/filesystem/operations.cpp
+++ b/src/filesystem/operations.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__utility/unreachable.h>
 #include <array>
 #include <climits>
diff --git a/src/filesystem/posix_compat.h b/src/filesystem/posix_compat.h
index 6cd6650..36116ec 100644
--- a/src/filesystem/posix_compat.h
+++ b/src/filesystem/posix_compat.h
@@ -23,6 +23,7 @@
 #ifndef POSIX_COMPAT_H
 #define POSIX_COMPAT_H
 
+#include <__assert>
 #include <filesystem>
 
 #include "filesystem_common.h"
diff --git a/src/include/ryu/common.h b/src/include/ryu/common.h
index 5291312..c24115c 100644
--- a/src/include/ryu/common.h
+++ b/src/include/ryu/common.h
@@ -42,6 +42,7 @@
 // Avoid formatting to keep the changes with the original code minimal.
 // clang-format off
 
+#include <__assert>
 #include "__config"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
diff --git a/src/include/ryu/d2s_intrinsics.h b/src/include/ryu/d2s_intrinsics.h
index 093d858..762763f 100644
--- a/src/include/ryu/d2s_intrinsics.h
+++ b/src/include/ryu/d2s_intrinsics.h
@@ -42,6 +42,7 @@
 // Avoid formatting to keep the changes with the original code minimal.
 // clang-format off
 
+#include <__assert>
 #include <__config>
 
 #include "include/ryu/ryu.h"
diff --git a/src/include/to_chars_floating_point.h b/src/include/to_chars_floating_point.h
index 3f8d361..0bb45d0 100644
--- a/src/include/to_chars_floating_point.h
+++ b/src/include/to_chars_floating_point.h
@@ -21,6 +21,7 @@
 #include <__algorithm/find_if.h>
 #include <__algorithm/lower_bound.h>
 #include <__algorithm/min.h>
+#include <__assert>
 #include <__config>
 #include <__iterator/access.h>
 #include <__iterator/size.h>
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 9e780aa..01b7420 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <limits>
 #include <mutex>
 #include <system_error>
diff --git a/src/ryu/d2fixed.cpp b/src/ryu/d2fixed.cpp
index bb6d621..c1a1f6c 100644
--- a/src/ryu/d2fixed.cpp
+++ b/src/ryu/d2fixed.cpp
@@ -39,6 +39,7 @@
 // Avoid formatting to keep the changes with the original code minimal.
 // clang-format off
 
+#include <__assert>
 #include <__config>
 #include <charconv>
 #include <cstring>
diff --git a/src/ryu/d2s.cpp b/src/ryu/d2s.cpp
index e22bfa4..245c2eb 100644
--- a/src/ryu/d2s.cpp
+++ b/src/ryu/d2s.cpp
@@ -39,6 +39,7 @@
 // Avoid formatting to keep the changes with the original code minimal.
 // clang-format off
 
+#include <__assert>
 #include <__config>
 #include <charconv>
 
diff --git a/src/ryu/f2s.cpp b/src/ryu/f2s.cpp
index e7d46d2..3bcfe46 100644
--- a/src/ryu/f2s.cpp
+++ b/src/ryu/f2s.cpp
@@ -39,6 +39,7 @@
 // Avoid formatting to keep the changes with the original code minimal.
 // clang-format off
 
+#include <__assert>
 #include <__config>
 #include <charconv>
 
diff --git a/src/string.cpp b/src/string.cpp
index db7d7d5..9d1de0c 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <__debug>
+#include <__assert>
 #include <cerrno>
 #include <charconv>
 #include <cstdlib>
diff --git a/src/strstream.cpp b/src/strstream.cpp
index c3a7eb9..87c235a 100644
--- a/src/strstream.cpp
+++ b/src/strstream.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__utility/unreachable.h>
-#include <__debug>
 #include <algorithm>
 #include <climits>
 #include <cstdlib>
diff --git a/src/support/ibm/xlocale_zos.cpp b/src/support/ibm/xlocale_zos.cpp
index 90c1ba9..a3f9558 100644
--- a/src/support/ibm/xlocale_zos.cpp
+++ b/src/support/ibm/xlocale_zos.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__support/ibm/xlocale.h>
 #include <sstream>
 #include <vector>
diff --git a/src/system_error.cpp b/src/system_error.cpp
index 1c45702..66db76c 100644
--- a/src/system_error.cpp
+++ b/src/system_error.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__assert>
 #include <__config>
-#include <__debug>
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>