aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/except.cc
diff options
context:
space:
mode:
authorNina Ranns <dinka.ranns@gmail.com>2024-07-11 17:47:34 +0100
committerJason Merrill <jason@redhat.com>2024-07-16 14:51:52 -0400
commit40a990c8b512fd25bd7d7b45aa509e1880d77209 (patch)
treecdb8f98be93407ace4baf5664ef77259ad43a90d /gcc/cp/except.cc
parenta3d1469c7c7e152fa7a5dbc95dbc6d1f3792bbd8 (diff)
downloadgcc-40a990c8b512fd25bd7d7b45aa509e1880d77209.zip
gcc-40a990c8b512fd25bd7d7b45aa509e1880d77209.tar.gz
gcc-40a990c8b512fd25bd7d7b45aa509e1880d77209.tar.bz2
c++/contracts: ICE in C++ Contracts with '-fno-exceptions' [PR 110159]
We currently only initialise terminate_fn if exceptions are enabled. However, contract handling requires terminate_fn when building the contract because a contract failure may result in std::terminate call regardless of whether the exceptions are enabled. Refactored init_exception_processing to extract the initialisation of terminate_fn. New function init_terminate_fn added that initialises terminate_fn if it hasn't already been initialised. Call to terminate_fn added in cxx_init_decl_processing if contracts are enabled. PR c++/110159 gcc/cp/ChangeLog: * cp-tree.h (init_terminate_fn): Declaration of a new function. * decl.cc (cxx_init_decl_processing): If contracts are enabled, call init_terminate_fn. * except.cc (init_exception_processing): Function refactored to call init_terminate_fn. (init_terminate_fn): Added new function that initializes terminate_fn if it hasn't already been initialised. gcc/testsuite/ChangeLog: * g++.dg/contracts/pr110159.C: New test. Signed-off-by: Nina Ranns <dinka.ranns@gmail.com>
Diffstat (limited to 'gcc/cp/except.cc')
-rw-r--r--gcc/cp/except.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc
index 1eb3ba5..3c69ab6 100644
--- a/gcc/cp/except.cc
+++ b/gcc/cp/except.cc
@@ -42,15 +42,17 @@ static tree wrap_cleanups_r (tree *, int *, void *);
static bool is_admissible_throw_operand_or_catch_parameter (tree, bool,
tsubst_flags_t);
-/* Sets up all the global eh stuff that needs to be initialized at the
- start of compilation. */
+/* Initializes the node to std::terminate, which is used in exception
+ handling and contract handling. */
void
-init_exception_processing (void)
+init_terminate_fn (void)
{
+ if (terminate_fn)
+ return;
+
tree tmp;
- /* void std::terminate (); */
push_nested_namespace (std_node);
tmp = build_function_type_list (void_type_node, NULL_TREE);
terminate_fn = build_cp_library_fn_ptr ("terminate", tmp,
@@ -60,6 +62,19 @@ init_exception_processing (void)
&& TREE_NOTHROW (terminate_fn));
pop_nested_namespace (std_node);
+}
+
+/* Sets up all the global eh stuff that needs to be initialized at the
+ start of compilation. */
+
+void
+init_exception_processing (void)
+{
+ tree tmp;
+
+ /* void std::terminate (); */
+ init_terminate_fn ();
+
/* void __cxa_call_unexpected(void *); */
tmp = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
call_unexpected_fn