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? Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."