This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH for c++/15764 (adds new pre-lowering EH optimization pass)
Jason Merrill wrote:
Richard Guenther wrote:
This seems to break the gmp testsuite which now complains about non-freed
memory. In fact, for a reduced t-assign.cc
Fixed thus.
Tested x86_64-pc-linux-gnu, applied to trunk.
2007-10-14 Jason Merrill <jason@redhat.com>
* tree-eh.c (optimize_double_finally): Don't assume that the
cleanup we're duplicating is only one statement.
Index: tree-eh.c
===================================================================
*** tree-eh.c (revision 129310)
--- tree-eh.c (working copy)
*************** optimize_double_finally (tree one, tree
*** 2157,2174 ****
if (same_handler_p (TREE_OPERAND (oneh, 1), TREE_OPERAND (two, 1)))
{
- tree twoh;
-
tree b = TREE_OPERAND (oneh, 0);
TREE_OPERAND (one, 1) = b;
TREE_SET_CODE (one, TRY_CATCH_EXPR);
! b = tsi_stmt (tsi_start (b));
! twoh = TREE_OPERAND (two, 0);
! /* same_handler_p only handles single-statement handlers,
! so there must only be one statement. */
! i = tsi_start (twoh);
! tsi_link_before (&i, unshare_expr (b), TSI_SAME_STMT);
}
}
--- 2157,2168 ----
if (same_handler_p (TREE_OPERAND (oneh, 1), TREE_OPERAND (two, 1)))
{
tree b = TREE_OPERAND (oneh, 0);
TREE_OPERAND (one, 1) = b;
TREE_SET_CODE (one, TRY_CATCH_EXPR);
! i = tsi_start (TREE_OPERAND (two, 0));
! tsi_link_before (&i, unsave_expr_now (b), TSI_SAME_STMT);
}
}
Index: testsuite/g++.dg/eh/ehopt1.C
===================================================================
*** testsuite/g++.dg/eh/ehopt1.C (revision 0)
--- testsuite/g++.dg/eh/ehopt1.C (revision 0)
***************
*** 0 ****
--- 1,44 ----
+ // ehopt was only copying one statement from the cleanup of the B temporary
+ // into the following try block, so we lost its destructor call.
+
+ // { dg-do run }
+
+ template <class T, class U>
+ class A;
+
+ bool b;
+ int count;
+
+ template <>
+ class A<int, int>
+ {
+ public:
+ A(int) { ++count; if (b) throw 1; }
+ A(const A&) { ++count; if (b) throw 1; }
+ ~A() { --count; if (b) throw 1; }
+ };
+
+ typedef A<int, int> B;
+
+ template <>
+ class A<void *, void *>
+ {
+ public:
+ A() { if (b) throw 1; }
+ A(const B&) { if (b) throw 1; }
+ ~A() { if (b) throw 1; }
+ };
+
+ typedef A<void *, void *> C;
+
+ void f() { if (b) throw 1; }
+
+ int
+ main (void)
+ {
+ {
+ C a(1);
+ f();
+ }
+ return count;
+ }