[libcxx-commits] [libcxx] c9c3cdd - [libc++] Use _LIBCPP_VERBOSE_ABORT in a few remaining __throw_FOO functions

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 17 15:00:15 PDT 2023


Author: Louis Dionne
Date: 2023-07-17T18:00:03-04:00
New Revision: c9c3cddb5e99a4d73a29580e1ba4cd8165424bab

URL: https://github.com/llvm/llvm-project/commit/c9c3cddb5e99a4d73a29580e1ba4cd8165424bab
DIFF: https://github.com/llvm/llvm-project/commit/c9c3cddb5e99a4d73a29580e1ba4cd8165424bab.diff

LOG: [libc++] Use _LIBCPP_VERBOSE_ABORT in a few remaining __throw_FOO functions

This provides better error messages when the program terminates due to
an exception being thrown in -fno-exceptions mode. Those seem to have
been missed in https://reviews.llvm.org/D141222.

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

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/__format/format_error.h
    libcxx/src/locale.cpp
    libcxx/src/string.cpp
    libcxx/src/system_error.cpp
    libcxx/test/libcxx/transitive_includes/cxx03.csv
    libcxx/test/libcxx/transitive_includes/cxx11.csv
    libcxx/test/libcxx/transitive_includes/cxx14.csv
    libcxx/test/libcxx/transitive_includes/cxx17.csv
    libcxx/test/libcxx/transitive_includes/cxx20.csv
    libcxx/test/libcxx/transitive_includes/cxx23.csv
    libcxx/test/libcxx/transitive_includes/cxx26.csv

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index b93c2c86994ebd..f5b568fa4ef479 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -143,6 +143,8 @@ Deprecations and Removals
 - ``<atomic>``, ``<barrier>``, ``<latch>``, ``<numeric>``, ``<semaphore>`` and ``<shared_mutex>`` no longer include ``<iosfwd>``
   (it was previously included in all Standard versions).
 
+- ``<format>``, ``<chrono>`` and ``<thread>`` no longer transitively include ``<cstdlib>``.
+
 - The headers ``<experimental/algorithm>`` and ``<experimental/functional>`` have been removed, since all the contents
   have been implemented in namespace ``std`` for at least two releases.
 

diff  --git a/libcxx/include/__format/format_error.h b/libcxx/include/__format/format_error.h
index 5faea1ce0316da..f22cb0b81ec2e3 100644
--- a/libcxx/include/__format/format_error.h
+++ b/libcxx/include/__format/format_error.h
@@ -11,7 +11,7 @@
 #define _LIBCPP___FORMAT_FORMAT_ERROR_H
 
 #include <__config>
-#include <cstdlib>
+#include <__verbose_abort>
 #include <stdexcept>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -40,8 +40,7 @@ __throw_format_error(const char* __s) {
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
   throw format_error(__s);
 #else
-  (void)__s;
-  _VSTD::abort();
+  _LIBCPP_VERBOSE_ABORT("format_error was thrown in -fno-exceptions mode with message \"%s\"", __s);
 #endif
 }
 

diff  --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index 1eea9cf8c1fc75..bd70a27be4ef7b 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <__utility/unreachable.h>
+#include <__verbose_abort>
 #include <algorithm>
 #include <clocale>
 #include <codecvt>
@@ -115,8 +116,7 @@ _LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw runtime_error(msg);
 #else
-    (void)msg;
-    _VSTD::abort();
+    _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg.c_str());
 #endif
 }
 
@@ -6532,8 +6532,7 @@ void __throw_runtime_error(const char* msg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw runtime_error(msg);
 #else
-    (void)msg;
-    _VSTD::abort();
+    _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg);
 #endif
 }
 

diff  --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp
index 01313e68181bc9..3d671bccdc6e0b 100644
--- a/libcxx/src/string.cpp
+++ b/libcxx/src/string.cpp
@@ -12,7 +12,6 @@
 #include <cstdlib>
 #include <limits>
 #include <stdexcept>
-#include <stdio.h>
 #include <string>
 
 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
@@ -61,22 +60,12 @@ template string operator+<char, char_traits<char>, allocator<char>>(char const*,
 namespace
 {
 
-template<typename T>
-inline void throw_helper(const string& msg) {
-#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
-    throw T(msg);
-#else
-    fprintf(stderr, "%s\n", msg.c_str());
-    _VSTD::abort();
-#endif
-}
-
 inline void throw_from_string_out_of_range(const string& func) {
-    throw_helper<out_of_range>(func + ": out of range");
+    std::__throw_out_of_range((func + ": out of range").c_str());
 }
 
 inline void throw_from_string_invalid_arg(const string& func) {
-    throw_helper<invalid_argument>(func + ": no conversion");
+    std::__throw_invalid_argument((func + ": no conversion").c_str());
 }
 
 // as_integer

diff  --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp
index 1502c7de6ba551..7875f59d88075b 100644
--- a/libcxx/src/system_error.cpp
+++ b/libcxx/src/system_error.cpp
@@ -12,6 +12,7 @@
 #endif
 
 #include <__assert>
+#include <__verbose_abort>
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>
@@ -289,9 +290,7 @@ __throw_system_error(int ev, const char* what_arg)
 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
     throw system_error(error_code(ev, system_category()), what_arg);
 #else
-    (void)ev;
-    (void)what_arg;
-    _VSTD::abort();
+    _LIBCPP_VERBOSE_ABORT("system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg);
 #endif
 }
 

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 495d23acc3f6eb..7a6ba4f3b0f3cd 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -116,7 +116,6 @@ chrono compare
 chrono concepts
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono cstring
 chrono ctime
 chrono limits
@@ -302,7 +301,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -857,7 +855,6 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index 319be83224481e..cfce8c074265de 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -116,7 +116,6 @@ chrono compare
 chrono concepts
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono cstring
 chrono ctime
 chrono limits
@@ -302,7 +301,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -858,7 +856,6 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index 9c4df80aebda37..7c6e8c947394d0 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -116,7 +116,6 @@ chrono compare
 chrono concepts
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono cstring
 chrono ctime
 chrono limits
@@ -304,7 +303,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -860,7 +858,6 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 9c4df80aebda37..7c6e8c947394d0 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -116,7 +116,6 @@ chrono compare
 chrono concepts
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono cstring
 chrono ctime
 chrono limits
@@ -304,7 +303,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -860,7 +858,6 @@ thread chrono
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index ef5ba26a52f9b0..603d7892b38b0a 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -118,7 +118,6 @@ chrono compare
 chrono concepts
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono cstring
 chrono ctime
 chrono limits
@@ -311,7 +310,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -865,7 +863,6 @@ thread cerrno
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread cstring
 thread ctime
 thread functional

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index 2745d93bcec557..c1cd8e97fc48d8 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -71,7 +71,6 @@ chrono cmath
 chrono compare
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono ctime
 chrono initializer_list
 chrono limits
@@ -214,7 +213,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -615,7 +613,6 @@ thread cerrno
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread ctime
 thread initializer_list
 thread iosfwd
@@ -691,7 +688,6 @@ vector climits
 vector compare
 vector cstddef
 vector cstdint
-vector cstdlib
 vector cstring
 vector cwchar
 vector initializer_list

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 2745d93bcec557..c1cd8e97fc48d8 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -71,7 +71,6 @@ chrono cmath
 chrono compare
 chrono cstddef
 chrono cstdint
-chrono cstdlib
 chrono ctime
 chrono initializer_list
 chrono limits
@@ -214,7 +213,6 @@ format array
 format cmath
 format cstddef
 format cstdint
-format cstdlib
 format initializer_list
 format limits
 format locale
@@ -615,7 +613,6 @@ thread cerrno
 thread compare
 thread cstddef
 thread cstdint
-thread cstdlib
 thread ctime
 thread initializer_list
 thread iosfwd
@@ -691,7 +688,6 @@ vector climits
 vector compare
 vector cstddef
 vector cstdint
-vector cstdlib
 vector cstring
 vector cwchar
 vector initializer_list


        


More information about the libcxx-commits mailing list