Messages in this thread | | | From | Roland Dreier <> | Subject | Re: [PATCH] log2.h: Macro-ize is_power_of_2() for use in BUILD_BUG_ON | Date | Wed, 06 Jan 2010 13:23:13 -0800 |
| |
> 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.
| |