This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[hsa 9/12] Small alloc-pool fix


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  <mliska@suse.cz>
	    Martin Jambor  <mjambor@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.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]