Re: [PATCH] log2.h: Macro-ize is_power_of_2() for use in BUILD_BUG_ON

From: Roland Dreier
Date: Wed Jan 06 2010 - 16:23:20 EST



> We've had recurring struggles with various versions of gcc screwing up
> constructs of this form and trying to emit the non-constant code when
> the arg was clearly a compile-time constant. One episode which comes
> to mind was when we made changes to kmalloc().
>
> Of course, that might not bite us in this case - it would need a lot of
> coverage testing to find out.

Actually, after thinking about this a bit more I don't think this is
much of a risk in this case. The bad case is where gcc gets the wrong
answer for __builtin_constant_p(), and in that case, we're left with the
status quo ante, ie a call to the original inline function implementation.

This will break a call to BUILD_BUG_ON() but that's visible at compile
time. It's hard to think of a silent failure case that actually hurts
anything -- the macro and inline implementation are identical, except
that the macro implementation will work when gcc really needs a compile
time constant.

- R.
--
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/