Re: Question on FIELD_PREP() for static array
From: Johannes Berg
Date: Thu Oct 11 2018 - 15:13:36 EST
On Thu, 2018-10-11 at 18:26 +0100, John Garry wrote:
> > > Yeah, I have a patch now to reference it, but I don't see anything from
> > > -Wvla with gcc 8.1?
> >
> > I'm using a 7.3.1-based toolchain
> >
> > >
> > > See
> > > https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git/commit/?id=3d7af878357acd9e37fc156928106f1a969c8942
> > >
> > > and its parent.
> > >
> > > Do you see -Wvla warnings there? Any idea how I could reproduce them?
> >
> > I'll try it, thanks
>
> 3d7af878357acd9e37f builds ok. However I am using 20181010-next (I'm not
> sure what yours is based on), and I just noticed that it includes this
> new guy:
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/Makefile?h=next-20181011&id=bc5701d8e27fd8beaf895176982fc6a97878f3b
Right, but I added -Wvla by adding subdir-ccflags-y to my Makefile for
this test, and I don't see the warning.
I tried with gcc 7.3.1 too now (Fedora 27) and it doesn't provoke the
warning, even if apply bc5701d8e27fd (manually). I did ensure with V=1
that it shows up on the compiler command line.
This is on x86-64, are you using something else?
Hmm.
However, I have another trick:
#define __NLA_ENSURE(condition) (0 * sizeof(struct { unsigned int x:1 - 2*!(condition);}))
or, in this context,
#define BUILD_BUG_ON_RET_ZERO(cond) (0 * sizeof(struct { unsigned int x:1 - 2*!(condition);}))
What do you think?
johannes