C++ PATCH: PR 16698
Mark Mitchell
mark@codesourcery.com
Thu Aug 12 06:26:00 GMT 2004
This patch fixes PR c++/16698, a crash when there was an explicit
declaration of __cxa_throw.
Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-08-11 Mark Mitchell <mark@codesourcery.com>
PR c++/16698
* except.c (build_throw): Allocate cleanup_type and the function
for __cxa_throw separately.
2004-08-11 Mark Mitchell <mark@codesourcery.com>
PR c++/16698
* g++.dg/eh/crash1.C: New test.
Index: cp/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.171
diff -c -5 -p -r1.171 except.c
*** cp/except.c 20 Jul 2004 00:34:00 -0000 1.171
--- cp/except.c 12 Aug 2004 05:14:28 -0000
*************** build_throw (tree exp)
*** 609,640 ****
tree object, ptr;
tree tmp;
tree temp_expr, allocate_expr;
bool elided;
fn = get_identifier ("__cxa_throw");
if (!get_global_value_if_present (fn, &fn))
{
- /* The CLEANUP_TYPE is the internal type of a destructor. */
- if (cleanup_type == NULL_TREE)
- {
- tmp = void_list_node;
- tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
- tmp = build_function_type (void_type_node, tmp);
- cleanup_type = build_pointer_type (tmp);
- }
-
/* Declare void __cxa_throw (void*, void*, void (*)(void*)). */
/* ??? Second argument is supposed to be "std::type_info*". */
tmp = void_list_node;
tmp = tree_cons (NULL_TREE, cleanup_type, tmp);
tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
tmp = build_function_type (void_type_node, tmp);
fn = push_throw_library_fn (fn, tmp);
}
!
/* throw expression */
/* First, decay it. */
exp = decay_conversion (exp);
/* OK, this is kind of wacky. The standard says that we call
--- 609,640 ----
tree object, ptr;
tree tmp;
tree temp_expr, allocate_expr;
bool elided;
+ /* The CLEANUP_TYPE is the internal type of a destructor. */
+ if (!cleanup_type)
+ {
+ tmp = void_list_node;
+ tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
+ tmp = build_function_type (void_type_node, tmp);
+ cleanup_type = build_pointer_type (tmp);
+ }
+
fn = get_identifier ("__cxa_throw");
if (!get_global_value_if_present (fn, &fn))
{
/* Declare void __cxa_throw (void*, void*, void (*)(void*)). */
/* ??? Second argument is supposed to be "std::type_info*". */
tmp = void_list_node;
tmp = tree_cons (NULL_TREE, cleanup_type, tmp);
tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
tmp = build_function_type (void_type_node, tmp);
fn = push_throw_library_fn (fn, tmp);
}
!
/* throw expression */
/* First, decay it. */
exp = decay_conversion (exp);
/* OK, this is kind of wacky. The standard says that we call
Index: testsuite/g++.dg/eh/crash1.C
===================================================================
RCS file: testsuite/g++.dg/eh/crash1.C
diff -N testsuite/g++.dg/eh/crash1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/eh/crash1.C 12 Aug 2004 05:14:29 -0000
***************
*** 0 ****
--- 1,5 ----
+ extern "C" void __cxa_throw (void *, void *, void (*) (void *) );
+
+ void foo(){
+ throw 1;
+ }
More information about the Gcc-patches
mailing list