From 5929c659186adc165b6cc32aab2890a1629d667a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 26 Oct 2015 09:48:32 +0000 Subject: [PATCH] alloc-pool.h (base_pool_allocator): Use placement new. 2015-10-26 Richard Biener * alloc-pool.h (base_pool_allocator): Use placement new. (base_pool_allocator::remove): Likewise. Compute size outside of flag_checking. From-SVN: r229312 --- gcc/ChangeLog | 6 ++++++ gcc/alloc-pool.h | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3285ca4ee41..cf6e87fb1ab 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-10-26 Richard Biener + + * alloc-pool.h (base_pool_allocator): Use placement new. + (base_pool_allocator::remove): Likewise. Compute size outside of + flag_checking. + 2015-10-26 Richard Sandiford * builtins.c (do_real_to_int_conversion): New function. diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h index 404b558e027..0dc05cdb719 100644 --- a/gcc/alloc-pool.h +++ b/gcc/alloc-pool.h @@ -363,7 +363,7 @@ base_pool_allocator ::allocate () /* Make the block. */ block = reinterpret_cast (TBlockAllocator::allocate ()); - block_header = (allocation_pool_list*) block; + block_header = new (block) allocation_pool_list; block += align_eight (sizeof (allocation_pool_list)); /* Throw it on the block list. */ @@ -414,6 +414,8 @@ template inline void base_pool_allocator ::remove (void *object) { + int size = m_elt_size - offsetof (allocation_object, u.data); + if (flag_checking) { gcc_assert (m_initialized); @@ -423,14 +425,13 @@ base_pool_allocator ::remove (void *object) /* Check whether the PTR was allocated from POOL. */ && m_id == allocation_object::get_instance (object)->id); - int size = m_elt_size - offsetof (allocation_object, u.data); memset (object, 0xaf, size); } /* Mark the element to be free. */ allocation_object::get_instance (object)->id = 0; - allocation_pool_list *header = (allocation_pool_list*) object; + allocation_pool_list *header = new (object) allocation_pool_list; header->next = m_returned_free_list; m_returned_free_list = header; VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (object, size)); -- 2.30.2