diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-14 00:31:10 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-14 00:31:10 +0100 |
| commit | c26e0082091065db907d76b6e560c6d87dfd3fb0 (patch) | |
| tree | b7ad1bd3eefc614da2cbd89dd24ffd8e3f7d97e7 /src | |
| parent | Add reference to clang bug report (diff) | |
| download | libzahl-c26e0082091065db907d76b6e560c6d87dfd3fb0.tar.gz libzahl-c26e0082091065db907d76b6e560c6d87dfd3fb0.tar.bz2 libzahl-c26e0082091065db907d76b6e560c6d87dfd3fb0.tar.xz | |
Cleaner workaround for clang bug
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/allocator.c | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/src/allocator.c b/src/allocator.c index fd821a9..e75546f 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -1,44 +1,27 @@ /* See LICENSE file for copyright and license details. */ #include "internals.h" -#include <stdio.h> - - -/* Find r such that r is a minimal power of 2 ≥ n. */ -#define NEXT_2POW(n)\ - do if (likely((n & (~n + 1)) != n)) {\ - size_t x;\ - n |= n >> 1;\ - n |= n >> 2;\ - n |= n >> 4;\ - for (i = sizeof(n), x = 8; i; i >>= 1, x <<= 1)\ - n |= n >> x;\ - n += 1;\ - } while (0) - - -#if defined(__clang__) -static inline __attribute__((optnone)) size_t -clang_warkaround_next_2pow(size_t need) -{ - size_t i; - NEXT_2POW(need); - return need; -} -#endif void libzahl_realloc(z_t a, size_t need) { - size_t i; - zahl_char_t *new; - -#if defined(__clang__) - /* https://llvm.org/bugs/show_bug.cgi?id=26930 */ - need = clang_warkaround_next_2pow(need); +#if defined(__clang__) /* https://llvm.org/bugs/show_bug.cgi?id=26930 */ + volatile size_t j; #else - NEXT_2POW(need); +# define j i #endif + size_t i, x; + zahl_char_t *new; + + /* Find n such that n is a minimal power of 2 ≥ need. */ + if (likely((need & (~need + 1)) != need)) { + need |= need >> 1; + need |= need >> 2; + need |= need >> 4; + for (j = sizeof(need), x = 8; j; j >>= 1, x <<= 1) + need |= need >> x; + need += 1; + } i = libzahl_msb_nz_zu(need); |
