Hi, we use C++ new operators based on alloc-pools a lot in the subsequent patches and realized that on the current trunk, such new operators would needlessly call the placement ::new operator within the allocate method of pool-alloc. Fixed below by providing a new allocation method which does not call placement new, which is only safe to use from within a new operator.
The patch also fixes the slightly weird two parameter operator new (which we do not use in HSA backend) so that it does not do the same. Thanks, Martin 2015-11-05 Martin Liska <mli...@suse.cz> Martin Jambor <mjam...@suse.cz> * alloc-pool.h (object_allocator::vallocate): New method. (operator new): Call vallocate instead of allocate. (operator new): New operator. diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h index 0dc05cd..46b6550 100644 --- a/gcc/alloc-pool.h +++ b/gcc/alloc-pool.h @@ -483,6 +483,12 @@ public: return ::new (m_allocator.allocate ()) T (); } + inline void * + vallocate () ATTRIBUTE_MALLOC + { + return m_allocator.allocate (); + } + inline void remove (T *object) { @@ -523,12 +529,19 @@ struct alloc_pool_descriptor }; /* Helper for classes that do not provide default ctor. */ - template <typename T> inline void * operator new (size_t, object_allocator<T> &a) { - return a.allocate (); + return a.vallocate (); +} + +/* Helper for classes that do not provide default ctor. */ +template <typename T> +inline void * +operator new (size_t, object_allocator<T> *a) +{ + return a->vallocate (); } /* Hashtable mapping alloc_pool names to descriptors. */