diff options
| -rw-r--r-- | include/linux/bug.h | 61 | ||||
| -rw-r--r-- | include/linux/kernel.h | 61 |
2 files changed, 61 insertions, 61 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h index d276b5510c83..72961c39576a 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h | |||
| @@ -11,6 +11,67 @@ enum bug_trap_type { | |||
| 11 | 11 | ||
| 12 | struct pt_regs; | 12 | struct pt_regs; |
| 13 | 13 | ||
| 14 | #ifdef __CHECKER__ | ||
| 15 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) | ||
| 16 | #define BUILD_BUG_ON_ZERO(e) (0) | ||
| 17 | #define BUILD_BUG_ON_NULL(e) ((void*)0) | ||
| 18 | #define BUILD_BUG_ON(condition) | ||
| 19 | #define BUILD_BUG() (0) | ||
| 20 | #else /* __CHECKER__ */ | ||
| 21 | |||
| 22 | /* Force a compilation error if a constant expression is not a power of 2 */ | ||
| 23 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | ||
| 24 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | ||
| 25 | |||
| 26 | /* Force a compilation error if condition is true, but also produce a | ||
| 27 | result (of value 0 and type size_t), so the expression can be used | ||
| 28 | e.g. in a structure initializer (or where-ever else comma expressions | ||
| 29 | aren't permitted). */ | ||
| 30 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | ||
| 31 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | ||
| 32 | |||
| 33 | /** | ||
| 34 | * BUILD_BUG_ON - break compile if a condition is true. | ||
| 35 | * @condition: the condition which the compiler should know is false. | ||
| 36 | * | ||
| 37 | * If you have some code which relies on certain constants being equal, or | ||
| 38 | * other compile-time-evaluated condition, you should use BUILD_BUG_ON to | ||
| 39 | * detect if someone changes it. | ||
| 40 | * | ||
| 41 | * The implementation uses gcc's reluctance to create a negative array, but | ||
| 42 | * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments | ||
| 43 | * to inline functions). So as a fallback we use the optimizer; if it can't | ||
| 44 | * prove the condition is false, it will cause a link error on the undefined | ||
| 45 | * "__build_bug_on_failed". This error message can be harder to track down | ||
| 46 | * though, hence the two different methods. | ||
| 47 | */ | ||
| 48 | #ifndef __OPTIMIZE__ | ||
| 49 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) | ||
| 50 | #else | ||
| 51 | extern int __build_bug_on_failed; | ||
| 52 | #define BUILD_BUG_ON(condition) \ | ||
| 53 | do { \ | ||
| 54 | ((void)sizeof(char[1 - 2*!!(condition)])); \ | ||
| 55 | if (condition) __build_bug_on_failed = 1; \ | ||
| 56 | } while(0) | ||
| 57 | #endif | ||
| 58 | |||
| 59 | /** | ||
| 60 | * BUILD_BUG - break compile if used. | ||
| 61 | * | ||
| 62 | * If you have some code that you expect the compiler to eliminate at | ||
| 63 | * build time, you should use BUILD_BUG to detect if it is | ||
| 64 | * unexpectedly used. | ||
| 65 | */ | ||
| 66 | #define BUILD_BUG() \ | ||
| 67 | do { \ | ||
| 68 | extern void __build_bug_failed(void) \ | ||
| 69 | __linktime_error("BUILD_BUG failed"); \ | ||
| 70 | __build_bug_failed(); \ | ||
| 71 | } while (0) | ||
| 72 | |||
| 73 | #endif /* __CHECKER__ */ | ||
| 74 | |||
| 14 | #ifdef CONFIG_GENERIC_BUG | 75 | #ifdef CONFIG_GENERIC_BUG |
| 15 | #include <asm-generic/bug.h> | 76 | #include <asm-generic/bug.h> |
| 16 | 77 | ||
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 | ||
