diff options
author | Paul Gortmaker <paul.gortmaker@windriver.com> | 2011-11-16 23:51:05 -0500 |
---|---|---|
committer | Paul Gortmaker <paul.gortmaker@windriver.com> | 2012-03-04 17:54:35 -0500 |
commit | 35edd9103c84f2b37f63227d12765c38f30495c5 (patch) | |
tree | fd8afa6aee69f6353f7d0d6f927c6c5c2a6ecdd4 /include/linux/kernel.h | |
parent | 187f1882b5b0748b3c4c22274663fdb372ac0452 (diff) |
bug: consolidate BUILD_BUG_ON with other bug code
The support for BUILD_BUG in linux/kernel.h predates the
addition of linux/bug.h -- with this chunk off separate,
you can run into situations where a person gets a compile
fail even when they've included linux/bug.h, like this:
CC lib/string.o
lib/string.c: In function 'strlcat':
lib/string.c:225:2: error: implicit declaration of function 'BUILD_BUG_ON'
make[2]: *** [lib/string.o] Error 1
$
$ grep linux/bug.h lib/string.c
#include <linux/bug.h>
$
Since the above violates the principle of least surprise, move
the BUG chunks from kernel.h to bug.h so it is all together.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index e8343422240a..5dba983b8d65 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -662,67 +662,6 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
662 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | 662 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
663 | (type *)( (char *)__mptr - offsetof(type,member) );}) | 663 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
664 | 664 | ||
665 | #ifdef __CHECKER__ | ||
666 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) | ||
667 | #define BUILD_BUG_ON_ZERO(e) (0) | ||
668 | #define BUILD_BUG_ON_NULL(e) ((void*)0) | ||
669 | #define BUILD_BUG_ON(condition) | ||
670 | #define BUILD_BUG() (0) | ||
671 | #else /* __CHECKER__ */ | ||
672 | |||
673 | /* Force a compilation error if a constant expression is not a power of 2 */ | ||
674 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | ||
675 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | ||
676 | |||
677 | /* Force a compilation error if condition is true, but also produce a | ||
678 | result (of value 0 and type size_t), so the expression can be used | ||
679 | e.g. in a structure initializer (or where-ever else comma expressions | ||
680 | aren't permitted). */ | ||
681 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | ||
682 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | ||
683 | |||
684 | /** | ||
685 | * BUILD_BUG_ON - break compile if a condition is true. | ||
686 | * @condition: the condition which the compiler should know is false. | ||
687 | * | ||
688 | * If you have some code which relies on certain constants being equal, or | ||
689 | * other compile-time-evaluated condition, you should use BUILD_BUG_ON to | ||
690 | * detect if someone changes it. | ||
691 | * | ||
692 | * The implementation uses gcc's reluctance to create a negative array, but | ||
693 | * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments | ||
694 | * to inline functions). So as a fallback we use the optimizer; if it can't | ||
695 | * prove the condition is false, it will cause a link error on the undefined | ||
696 | * "__build_bug_on_failed". This error message can be harder to track down | ||
697 | * though, hence the two different methods. | ||
698 | */ | ||
699 | #ifndef __OPTIMIZE__ | ||
700 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) | ||
701 | #else | ||
702 | extern int __build_bug_on_failed; | ||
703 | #define BUILD_BUG_ON(condition) \ | ||
704 | do { \ | ||
705 | ((void)sizeof(char[1 - 2*!!(condition)])); \ | ||
706 | if (condition) __build_bug_on_failed = 1; \ | ||
707 | } while(0) | ||
708 | #endif | ||
709 | |||
710 | /** | ||
711 | * BUILD_BUG - break compile if used. | ||
712 | * | ||
713 | * If you have some code that you expect the compiler to eliminate at | ||
714 | * build time, you should use BUILD_BUG to detect if it is | ||
715 | * unexpectedly used. | ||
716 | */ | ||
717 | #define BUILD_BUG() \ | ||
718 | do { \ | ||
719 | extern void __build_bug_failed(void) \ | ||
720 | __linktime_error("BUILD_BUG failed"); \ | ||
721 | __build_bug_failed(); \ | ||
722 | } while (0) | ||
723 | |||
724 | #endif /* __CHECKER__ */ | ||
725 | |||
726 | /* Trap pasters of __FUNCTION__ at compile-time */ | 665 | /* Trap pasters of __FUNCTION__ at compile-time */ |
727 | #define __FUNCTION__ (__func__) | 666 | #define __FUNCTION__ (__func__) |
728 | 667 | ||