This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH to build_new_1 for c++/5757
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 17 Mar 2002 13:51:02 +0000
- Subject: PATCH to build_new_1 for c++/5757
Cleanup of the allocated pointer when a constructor throws wasn't working
properly, as we were passing the wrong pointer to op delete. Fixed thus.
Tested i686-pc-linux-gnu. Applied trunk and 3.1 branch. Test in
g++.dg/eh/new1.C.
2002-03-17 Jason Merrill <jason@redhat.com>
PR c++/5757
* init.c (build_new_1): Pass the right pointer to op delete.
*** init.c.~1~ Fri Mar 15 10:03:05 2002
--- init.c Sun Mar 17 12:21:18 2002
*************** build_new_1 (exp)
*** 2473,2485 ****
tree cleanup;
int flags = (LOOKUP_NORMAL
| (globally_qualified_p * LOOKUP_GLOBAL));
/* The Standard is unclear here, but the right thing to do
is to use the same method for finding deallocation
functions that we use for finding allocation functions. */
flags |= LOOKUP_SPECULATIVELY;
! cleanup = build_op_delete_call (dcode, alloc_node, size, flags,
(placement_allocation_fn_p
? alloc_call : NULL_TREE));
--- 2473,2494 ----
tree cleanup;
int flags = (LOOKUP_NORMAL
| (globally_qualified_p * LOOKUP_GLOBAL));
+ tree delete_node;
+
+ if (use_cookie)
+ /* Subtract the padding back out to get to the pointer returned
+ from operator new. */
+ delete_node = fold (build (MINUS_EXPR, TREE_TYPE (alloc_node),
+ alloc_node, cookie_size));
+ else
+ delete_node = alloc_node;
/* The Standard is unclear here, but the right thing to do
is to use the same method for finding deallocation
functions that we use for finding allocation functions. */
flags |= LOOKUP_SPECULATIVELY;
! cleanup = build_op_delete_call (dcode, delete_node, size, flags,
(placement_allocation_fn_p
? alloc_call : NULL_TREE));