On 10/6/20 6:40 AM, Andreas Schwab wrote:
On Okt 06 2020, Jakub Jelinek wrote:

On Tue, Oct 06, 2020 at 10:47:34AM +0200, Andreas Schwab wrote:
On Okt 06 2020, Jakub Jelinek via Gcc-patches wrote:

I mean, we could just use:
   size_t nbytes = sizeof (irange) + sizeof (tree) * 2 * num_pairs;
   irange *r = (irange *) obstack_alloc (&m_obstack, nbytes);
   return new (r) irange ((tree *) (r + 1), num_pairs);
without any new type.
Modulo proper alignment.
Sure, but irange's last element is tree * which is pointer to pointer,
and we need here an array of tree, i.e. pointers.  So, it would indeed break
on a hypothetical host that has smaller struct X ** alignment than struct X *
alignment.  I'm not aware of any.
One could add a static_assert to verify that (that alignof (irange) >= alignof 
(tree)
and that sizeof (irange) % alignof (tree) == 0).
I think the proper alignment will be guaranteed if irange and tree[] are
obstack_alloc'd separately.  They don't need to be adjacent, do they?


They do not, it just seemed wasteful to do 2 allocs each time, and it'd be nice to have them co-located since accessing one inevitable leads to accessing the other.



Reply via email to