[Bug libstdc++/95609] span<T> could have better layout

s_gccbugzilla at nedprod dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 23 13:51:21 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95609

--- Comment #8 from Niall Douglas <s_gccbugzilla at nedprod dot com> ---
(In reply to Jonathan Wakely from comment #7)
> (In reply to Niall Douglas from comment #0)
> > I would assume that the ABI ship has sailed, as usual, but if libstdc++'s
> > span<T> could instead have the layout:
> > 
> > {
> >   T *p;
> >   size_t l;
> > }
> > 
> > ... then a span<byte> would be layout-compatible with struct iovec,
> 
> No it won't, because iovec has a void* member, and span<byte> has a byte*
> member, which makes them not layout-compatible. Similarly for span<const
> char> or any other specialization of span.

It is indeed a shame that the compiler won't optimise this appropriately
without additional markup on the iovec structure:

https://godbolt.org/z/cTo5xPxjE

I can tell you that in LLFIO we simply reinterpret cast on those platforms
where we know they'll be bit identical because a bunch of static asserts
wouldn't have allowed compilation otherwise.

Niall


More information about the Gcc-bugs mailing list