Re: [PATCH v3 0/2] Stop some of the abuse of BUG() where compiletime checks should be used.
From: David Daney
Date: Wed Nov 23 2011 - 19:38:07 EST
On 11/23/2011 03:57 PM, Linus Torvalds wrote:
Btw, would it possibly make sense to make the string more useful?
For example using __FILE__ and __LINE__, or possibly letting the user
of the BUILD_BUG() give a string ("Using HMASK without
CONFIG_HUGEPAGE").
We thought about doing that, but without doing some complex preprocessor
fu, the GCC attribute ((error())) thing doesn't do what we want.
It appears that if more than a single instance of the construct is used
in a compilation unit, the string emitted by the compiler for any of the
violations will be the last string encountered.
So if you did something like:
.
.
.
Line 99: BUILD_BUG("You failed on line 99");
.
.
.
.
Line 666: BUILD_BUG("You failed on line 666");
.
.
.
The message emitted for a failure at line 99 would be "You failed on
line 666". Which is probably worse than no message at all.
It may be possible to do something like:
#define _LINENAME_CONCAT( _name_, _line_ ) _name_##_line_
#define _LINENAME(_name_, _line_) _LINENAME_CONCAT(_name_,_line_)
#define _BUILD_BUG(MSG,FUBAR) \
do { \
extern void FUBAR (void) \
__linktime_error("BUILD_BUG failed: " MSG); \
FUBAR (); \
} while (0)
#define BUILD_BUG(M,A) _BUILD_BUG(M, _LINENAME(__build_bug_failed,__LINE__))
But it didn't seem worth it.
Whatever. It's bikeshedding - what would probably be more important
would be to get this into linux-next so that we find out whether there
are any compile issues with it on other platforms or compiler
versions.
Linus
--
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/