From 448083e540b08bda3c373cf8ac9d32b5ea5314e2 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 27 Jul 2008 15:49:12 +0000 Subject: [PATCH] decl.c (push_library_fn): Add a parameter for the exceptions that the function may throw. 2008-07-27 Paolo Carlini * decl.c (push_library_fn): Add a parameter for the exceptions that the function may throw. (push_void_library_fn, push_throw_library_fn, expand_static_init): Adjust. (build_library_fn): Change to static. * cp-tree.h: Adjust declarations. * except.c (declare_nothrow_library_fn): New. (do_get_exception_ptr, do_begin_catch, do_free_exception, do_allocate_exception): Use the latter, adjust the declarations (ie, add empty exception-specification), consistently with the actual implementation in libsupc++. From-SVN: r138189 --- gcc/cp/ChangeLog | 14 ++++++++++++++ gcc/cp/cp-tree.h | 3 +-- gcc/cp/decl.c | 25 ++++++++++++++++--------- gcc/cp/except.c | 38 +++++++++++++++++++++++++------------- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b8e54a5..c40808e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +2008-07-27 Paolo Carlini + + * decl.c (push_library_fn): Add a parameter for the exceptions that + the function may throw. + (push_void_library_fn, push_throw_library_fn, expand_static_init): + Adjust. + (build_library_fn): Change to static. + * cp-tree.h: Adjust declarations. + * except.c (declare_nothrow_library_fn): New. + (do_get_exception_ptr, do_begin_catch, do_free_exception, + do_allocate_exception): Use the latter, adjust the declarations + (ie, add empty exception-specification), consistently with the + actual implementation in libsupc++. + 2008-07-25 Jan Hubicka * typeck.c (inline_conversion): Remove. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 13c1797..67f15e5 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4225,10 +4225,9 @@ extern bool check_omp_return (void); extern tree make_typename_type (tree, tree, enum tag_types, tsubst_flags_t); extern tree make_unbound_class_template (tree, tree, tree, tsubst_flags_t); extern tree check_for_out_of_scope_variable (tree); -extern tree build_library_fn (tree, tree); extern tree build_library_fn_ptr (const char *, tree); extern tree build_cp_library_fn_ptr (const char *, tree); -extern tree push_library_fn (tree, tree); +extern tree push_library_fn (tree, tree, tree); extern tree push_void_library_fn (tree, tree); extern tree push_throw_library_fn (tree, tree); extern tree check_tag_decl (cp_decl_specifier_seq *); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b762f68..0cc17a4 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3590,7 +3590,7 @@ build_library_fn_1 (tree name, enum tree_code operator_code, tree type) We assume that such functions never throw; if this is incorrect, callers should unset TREE_NOTHROW. */ -tree +static tree build_library_fn (tree name, tree type) { tree fn = build_library_fn_1 (name, ERROR_MARK, type); @@ -3629,12 +3629,18 @@ build_cp_library_fn_ptr (const char* name, tree type) } /* Like build_library_fn, but also pushes the function so that we will - be able to find it via IDENTIFIER_GLOBAL_VALUE. */ + be able to find it via IDENTIFIER_GLOBAL_VALUE. Also, the function + may throw exceptions listed in RAISES. */ tree -push_library_fn (tree name, tree type) +push_library_fn (tree name, tree type, tree raises) { - tree fn = build_library_fn (name, type); + tree fn; + + if (raises) + type = build_exception_variant (type, raises); + + fn = build_library_fn (name, type); pushdecl_top_level (fn); return fn; } @@ -3659,7 +3665,7 @@ tree push_void_library_fn (tree name, tree parmtypes) { tree type = build_function_type (void_type_node, parmtypes); - return push_library_fn (name, type); + return push_library_fn (name, type, NULL_TREE); } /* Like push_library_fn, but also note that this function throws @@ -3668,7 +3674,7 @@ push_void_library_fn (tree name, tree parmtypes) tree push_throw_library_fn (tree name, tree type) { - tree fn = push_library_fn (name, type); + tree fn = push_library_fn (name, type, NULL_TREE); TREE_THIS_VOLATILE (fn) = 1; TREE_NOTHROW (fn) = 0; return fn; @@ -6169,9 +6175,10 @@ expand_static_init (tree decl, tree init) void_list_node); tree vfntype = build_function_type (void_type_node, argtypes); acquire_fn = push_library_fn - (acquire_fn, build_function_type (integer_type_node, argtypes)); - release_fn = push_library_fn (release_fn, vfntype); - abort_fn = push_library_fn (abort_fn, vfntype); + (acquire_fn, build_function_type (integer_type_node, argtypes), + NULL_TREE); + release_fn = push_library_fn (release_fn, vfntype, NULL_TREE); + abort_fn = push_library_fn (abort_fn, vfntype, NULL_TREE); } else { diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 3070cda..adb1b97 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1,6 +1,7 @@ /* Handle exceptional things in C++. Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. + 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 + Free Software Foundation, Inc. Contributed by Michael Tiemann Rewritten by Mike Stump , based upon an initial re-implementation courtesy Tad Hunt. @@ -160,6 +161,21 @@ build_exc_ptr (void) return build0 (EXC_PTR_EXPR, ptr_type_node); } +/* Declare a function NAME, returning RETURN_TYPE, taking a single + parameter PARM_TYPE, with an empty exception specification. + + Note that the C++ ABI document does not have a throw-specifier on + the routines declared below via this function. The declarations + are consistent with the actual implementations in libsupc++. */ + +static tree +declare_nothrow_library_fn (tree name, tree return_type, tree parm_type) +{ + tree tmp = tree_cons (NULL_TREE, parm_type, void_list_node); + return push_library_fn (name, build_function_type (return_type, tmp), + empty_except_spec); +} + /* Build up a call to __cxa_get_exception_ptr so that we can build a copy constructor for the thrown object. */ @@ -171,9 +187,8 @@ do_get_exception_ptr (void) fn = get_identifier ("__cxa_get_exception_ptr"); if (!get_global_value_if_present (fn, &fn)) { - /* Declare void* __cxa_get_exception_ptr (void *). */ - tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); - fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp)); + /* Declare void* __cxa_get_exception_ptr (void *) throw(). */ + fn = declare_nothrow_library_fn (fn, ptr_type_node, ptr_type_node); } return cp_build_function_call (fn, tree_cons (NULL_TREE, build_exc_ptr (), @@ -192,9 +207,8 @@ do_begin_catch (void) fn = get_identifier ("__cxa_begin_catch"); if (!get_global_value_if_present (fn, &fn)) { - /* Declare void* __cxa_begin_catch (void *). */ - tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); - fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp)); + /* Declare void* __cxa_begin_catch (void *) throw(). */ + fn = declare_nothrow_library_fn (fn, ptr_type_node, ptr_type_node); } return cp_build_function_call (fn, tree_cons (NULL_TREE, build_exc_ptr (), @@ -543,9 +557,8 @@ do_allocate_exception (tree type) fn = get_identifier ("__cxa_allocate_exception"); if (!get_global_value_if_present (fn, &fn)) { - /* Declare void *__cxa_allocate_exception(size_t). */ - tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); - fn = push_library_fn (fn, build_function_type (ptr_type_node, tmp)); + /* Declare void *__cxa_allocate_exception(size_t) throw(). */ + fn = declare_nothrow_library_fn (fn, ptr_type_node, size_type_node); } return cp_build_function_call (fn, @@ -565,9 +578,8 @@ do_free_exception (tree ptr) fn = get_identifier ("__cxa_free_exception"); if (!get_global_value_if_present (fn, &fn)) { - /* Declare void __cxa_free_exception (void *). */ - fn = push_void_library_fn (fn, tree_cons (NULL_TREE, ptr_type_node, - void_list_node)); + /* Declare void __cxa_free_exception (void *) throw(). */ + fn = declare_nothrow_library_fn (fn, void_type_node, ptr_type_node); } return cp_build_function_call (fn, tree_cons (NULL_TREE, ptr, NULL_TREE), -- 2.7.4