]> git.karo-electronics.de Git - mv-sheeva.git/commit
BUILD_BUG_ON: make it handle more cases
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 24 Jan 2011 20:45:10 +0000 (14:45 -0600)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 24 Jan 2011 04:15:10 +0000 (14:45 +1030)
commit7ef88ad561457c0346355dfd1f53e503ddfde719
tree22f5e53aec61e0508f8d1aee130160fe24801144
parent1bae4ce27c9c90344f23c65ea6966c50ffeae2f5
BUILD_BUG_ON: make it handle more cases

BUILD_BUG_ON used to use the optimizer to do code elimination or fail
at link time; it was changed to first the size of a negative array (a
nicer compile time error), then (in
8c87df457cb58fe75b9b893007917cf8095660a0) to a bitfield.

This forced us to change some non-constant cases to MAYBE_BUILD_BUG_ON();
as Jan points out in that commit, it didn't work as intended anyway.

bitfields: needs a literal constant at parse time, and can't be put under
"if (__builtin_constant_p(x))" for example.
negative array: can handle anything, but if the compiler can't tell it's
a constant, silently has no effect.
link time: breaks link if the compiler can't determine the value, but the
linker output is not usually as informative as a compiler error.

If we use the negative-array-size method *and* the link time trick,
we get the ability to use BUILD_BUG_ON() under __builtin_constant_p()
branches, and maximal ability for the compiler to detect errors at
build time.

We also document it thoroughly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Jan Beulich <JBeulich@novell.com>
Acked-by: Hollis Blanchard <hollisb@us.ibm.com>
include/linux/kernel.h