public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Define <bits/functexcept.h> functions for freestanding [PR107135]
Date: Tue,  4 Oct 2022 15:11:35 +0100	[thread overview]
Message-ID: <20221004141138.530214-1-jwakely@redhat.com> (raw)

Tested powerpc64le-linux, and x86_64-linux with -ffreestanding.
Pushed to trunk.

-- >8 --

We don't compile src/c++11/functexcept.cc for freestanding, so just
define the functions used by freestanding entities as inline calls to
std::terminate.

libstdc++-v3/ChangeLog:

	PR libstdc++/107135
	* include/bits/functexcept.h [!_GLIBCXX_HOSTED]
	(__throw_invalid_argument, __throw_out_of_range)
	(__throw_out_of_range_fmt, __throw_runtime_error)
	(__throw_overflow_error): Define inline.
	* include/std/bitset (_M_copy_from_ptr) [!_GLIBCXX_HOSTED]:
	Replace __builtin_abort with __throw_invalid_argument.
---
 libstdc++-v3/include/bits/functexcept.h | 25 +++++++++++++++++++++++++
 libstdc++-v3/include/std/bitset         |  8 +-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/bits/functexcept.h b/libstdc++-v3/include/bits/functexcept.h
index a78a17b2e04..7fad4b13316 100644
--- a/libstdc++-v3/include/bits/functexcept.h
+++ b/libstdc++-v3/include/bits/functexcept.h
@@ -43,6 +43,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if _GLIBCXX_HOSTED
   // Helper for exception objects in <except>
   void
   __throw_bad_exception(void) __attribute__((__noreturn__));
@@ -112,6 +113,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   void
   __throw_bad_function_call() __attribute__((__noreturn__));
 
+#else // ! HOSTED
+
+  __attribute__((__noreturn__)) inline void
+  __throw_invalid_argument(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_out_of_range(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_out_of_range_fmt(const char*, ...)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_runtime_error(const char*)
+  { std::__terminate(); }
+
+  __attribute__((__noreturn__)) inline void
+  __throw_overflow_error(const char*)
+  { std::__terminate(); }
+
+#endif // HOSTED
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index afabeb4ba01..1f3f68fefce 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -1514,13 +1514,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	    else if (_Traits::eq(__c, __one))
 	      _Unchecked_set(__i - 1);
 	    else
-	      {
-#if _GLIBCXX_HOSTED
-		__throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
-#else
-		__builtin_abort();
-#endif
-	      }
+	      __throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
 	  }
       }
 
-- 
2.37.3


                 reply	other threads:[~2022-10-04 14:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221004141138.530214-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).