Re: [PATCH] BUILD_BUG_ON: make it handle more cases
From: Stephen Rothwell
Date: Thu Nov 05 2009 - 01:38:56 EST
On Thu, 5 Nov 2009 16:58:36 +1030 Rusty Russell <rusty@xxxxxxxxxxxxxxx> wrote:
> Huh? virtio_has_feature does:
> if (__builtin_constant_p(fbit))
> BUILD_BUG_ON(fbit >= 32);
> BUG_ON(fbit >= 32);
In Linus' tree (and linux-next) it looks like this:
static inline bool virtio_has_feature(const struct virtio_device *vdev,
unsigned int fbit)
/* Did you forget to fix assumptions on max features? */
MAYBE_BUILD_BUG_ON(fbit >= 32);
if (fbit < VIRTIO_TRANSPORT_F_START)
return test_bit(fbit, vdev->features);
> So, if it's not a constant, gcc should throw away that first branch. If it
> is, it should optimize it away (and no, these are not real bugs AFAICT).
Your version above may well fix the problem. Alternatively marking it
__always_inline way work as well.
> I did a 4.3.3 allmodconfig with this patch on 64-bit a few days back and all
> was fine. Will try 4.4.0 now.
4.4 is more problematic.
Stephen Rothwell sfr@xxxxxxxxxxxxxxxx
Description: PGP signature