This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[hsa 9/12] Small alloc-pool fix
- From: Martin Jambor <mjambor at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Martin Liska <mliska at suse dot cz>, Richard Biener <rguenther at suse dot de>
- Date: Thu, 5 Nov 2015 23:03:03 +0100
- Subject: [hsa 9/12] Small alloc-pool fix
- Authentication-results: sourceware.org; auth=none
- References: <20151105215108 dot GC9264 at virgil dot suse dot cz>
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. */