Re: [PATCH] fix BUILD_BUG_ON() and a couple of bogus uses of it

From: Andrew Morton
Date: Thu Sep 17 2009 - 19:25:21 EST


On Tue, 18 Aug 2009 16:59:25 +0100
"Jan Beulich" <JBeulich@xxxxxxxxxx> wrote:

> gcc permitting variable length arrays makes the current construct
> used for BUILD_BUG_ON() useless, as that doesn't produce any diagnostic
> if the controlling expression isn't really constant. Instead, this
> patch makes it so that a bit field gets used here. Consequently, those
> uses where the condition isn't really constant now also need fixing.
>
> Note that in the gfp.h, kmemcheck.h, and virtio_config.h cases
> MAYBE_BUILD_BUG_ON() really just serves documentation purposes - even
> if the expression is compile time constant (__builtin_constant_p()
> yields true), the array is still deemed of variable length by gcc, and
> hence the whole expression doesn't have the intended effect.

sparc64:

In file included from arch/sparc/kernel/vio.c:17:
/usr/src/devel/arch/sparc/include/asm/vio.h: In function `vio_dring_avail':
/usr/src/devel/arch/sparc/include/asm/vio.h:261: error: bit-field `<anonymous>' width not an integer constant

static inline u32 vio_dring_avail(struct vio_dring_state *dr,
unsigned int ring_size)
{
BUILD_BUG_ON(!is_power_of_2(ring_size));

return (dr->pending -
((dr->prod - dr->cons) & (ring_size - 1)));
}

changing it to MAYBE_BUILD_BUG_ON seems to have fixed it.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/