[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/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