summaryrefslogtreecommitdiffstats
path: root/include/linux/log2.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-03-02 15:17:22 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-03-02 15:17:22 -0500
commit474c90156c8dcc2fa815e6716cc9394d7930cb9c (patch)
treed364b428209d8762ebe00d905ae23b3ad1f7e741 /include/linux/log2.h
parent4977ab6e92e267afe9d8f78438c3db330ca8434c (diff)
give up on gcc ilog2() constant optimizations
gcc-7 has an "optimization" pass that completely screws up, and generates the code expansion for the (impossible) case of calling ilog2() with a zero constant, even when the code gcc compiles does not actually have a zero constant. And we try to generate a compile-time error for anybody doing ilog2() on a constant where that doesn't make sense (be it zero or negative). So now gcc7 will fail the build due to our sanity checking, because it created that constant-zero case that didn't actually exist in the source code. There's a whole long discussion on the kernel mailing about how to work around this gcc bug. The gcc people themselevs have discussed their "feature" in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785 but it's all water under the bridge, because while it looked at one point like it would be solved by the time gcc7 was released, that was not to be. So now we have to deal with this compiler braindamage. And the only simple approach seems to be to just delete the code that tries to warn about bad uses of ilog2(). So now "ilog2()" will just return 0 not just for the value 1, but for any non-positive value too. It's not like I can recall anybody having ever actually tried to use this function on any invalid value, but maybe the sanity check just meant that such code never made it out in public. Reported-by: Laura Abbott <labbott@redhat.com> Cc: John Stultz <john.stultz@linaro.org>, Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r--include/linux/log2.h13
1 files changed, 2 insertions, 11 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index ef3d4f67118c..c373295f359f 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -16,12 +16,6 @@
16#include <linux/bitops.h> 16#include <linux/bitops.h>
17 17
18/* 18/*
19 * deal with unrepresentable constant logarithms
20 */
21extern __attribute__((const, noreturn))
22int ____ilog2_NaN(void);
23
24/*
25 * non-constant log of base 2 calculators 19 * non-constant log of base 2 calculators
26 * - the arch may override these in asm/bitops.h if they can be implemented 20 * - the arch may override these in asm/bitops.h if they can be implemented
27 * more efficiently than using fls() and fls64() 21 * more efficiently than using fls() and fls64()
@@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
85#define ilog2(n) \ 79#define ilog2(n) \
86( \ 80( \
87 __builtin_constant_p(n) ? ( \ 81 __builtin_constant_p(n) ? ( \
88 (n) < 1 ? ____ilog2_NaN() : \ 82 (n) < 2 ? 0 : \
89 (n) & (1ULL << 63) ? 63 : \ 83 (n) & (1ULL << 63) ? 63 : \
90 (n) & (1ULL << 62) ? 62 : \ 84 (n) & (1ULL << 62) ? 62 : \
91 (n) & (1ULL << 61) ? 61 : \ 85 (n) & (1ULL << 61) ? 61 : \
@@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
148 (n) & (1ULL << 4) ? 4 : \ 142 (n) & (1ULL << 4) ? 4 : \
149 (n) & (1ULL << 3) ? 3 : \ 143 (n) & (1ULL << 3) ? 3 : \
150 (n) & (1ULL << 2) ? 2 : \ 144 (n) & (1ULL << 2) ? 2 : \
151 (n) & (1ULL << 1) ? 1 : \ 145 1 ) : \
152 (n) & (1ULL << 0) ? 0 : \
153 ____ilog2_NaN() \
154 ) : \
155 (sizeof(n) <= 4) ? \ 146 (sizeof(n) <= 4) ? \
156 __ilog2_u32(n) : \ 147 __ilog2_u32(n) : \
157 __ilog2_u64(n) \ 148 __ilog2_u64(n) \