[PATCH] treewide: improve strict-aliasing
Morten Brørup
mb at smartsharesystems.com
Fri Sep 11 17:23:34 CEST 2026
> From: Morten Brørup
> Sent: Monday, 31 August 2026 17.10
>
> > From: Robin Jarry [mailto:rjarry at redhat.com]
> > Sent: Monday, 31 August 2026 16.13
> >
> > Morten Brørup, Aug 31, 2026 at 08:36:
> > > Grout is built with -Wstrict-aliasing=2, which requires
> > > type casting to the generic "void *", like this:
> > >
> > > struct conn *conn;
> > > // create a new connection object
> > > if (rte_mempool_get(conn_pool, (void *)&conn) < 0)
> > > return NULL;
> > >
> > > Change to -Wstrict-aliasing=3, so we can use more accurate
> > > type casting, like this:
> > >
> > > struct conn *conn;
> > > // create a new connection object
> > > if (rte_mempool_get(conn_pool, (void **)&conn) < 0)
> > > return NULL;
> > >
> > > Grout currently compiles just fine with -Wstrict-aliasing=3.
> > >
> > > For reference, rte_mempool_get is declared as:
> > >
> > > static __rte_always_inline int
> > > rte_mempool_get(struct rte_mempool *mp, void **obj_p);
> > >
> > > Signed-off-by: Morten Brørup <mb at smartsharesystems.com>
> > > ---
> > > meson.build | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/meson.build b/meson.build
> > > index 144d1765..f0ac6ab6 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -33,7 +33,7 @@ endforeach
> > >
> > > # additional project C flags (keep alpha sorted)
> > > add_project_arguments('-Wmissing-prototypes', language: 'c')
> > > -add_project_arguments('-Wstrict-aliasing=2', language: 'c')
> > > +add_project_arguments('-Wstrict-aliasing=3', language: 'c')
> > > add_project_arguments('-fstrict-aliasing', language: 'c')
> > >
> > > # optional project C flags (keep alpha sorted)
> >
> > This would make sense to replace all (void *) blanket casts with more
> > appropriate ones in the same patch.
> >
> > Also, you could get rid of the now unnecessary intermediate void
> *data
> > variables since we can cast to (void **).
>
> OK, I'll see how much there is, and submit a patch including the code
> that can be improved as a consequence of this strict-aliasing
> adjustment.
Updated patch submitted:
https://github.com/DPDK/grout/pull/745
-Morten
More information about the grout
mailing list