| 1 |
/* Reduced from analyzer ICE seen with git-2.39.0's pack-bitmap.c |
| 2 |
when bounds-checking the result of __builtin_ctzll. */ |
| 3 |
|
| 4 |
#include <stdint.h> |
| 5 |
#include <stddef.h> |
| 6 |
|
| 7 |
typedef uint64_t eword_t; |
| 8 |
struct ewah_bitmap; |
| 9 |
struct ewah_iterator |
| 10 |
{ |
| 11 |
/* [...] */ |
| 12 |
}; |
| 13 |
struct bitmap; |
| 14 |
|
| 15 |
void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent); |
| 16 |
int ewah_iterator_next(eword_t *next, struct ewah_iterator *it); |
| 17 |
void bitmap_set(struct bitmap *self, size_t pos); |
| 18 |
|
| 19 |
int rebuild_bitmap(const uint32_t *reposition, |
| 20 |
struct ewah_bitmap *source, |
| 21 |
struct bitmap *dest) |
| 22 |
{ |
| 23 |
uint32_t pos = 0; |
| 24 |
struct ewah_iterator it; |
| 25 |
eword_t word; |
| 26 |
|
| 27 |
ewah_iterator_init(&it, source); |
| 28 |
|
| 29 |
while (ewah_iterator_next(&word, &it)) { |
| 30 |
uint32_t offset, bit_pos; |
| 31 |
|
| 32 |
for (offset = 0; offset < (sizeof(eword_t) * 8); ++offset) { |
| 33 |
if ((word >> offset) == 0) |
| 34 |
break; |
| 35 |
|
| 36 |
offset += __builtin_ctzll(word >> offset); |
| 37 |
|
| 38 |
bit_pos = reposition[pos + offset]; |
| 39 |
if (bit_pos > 0) |
| 40 |
bitmap_set(dest, bit_pos - 1); |
| 41 |
else |
| 42 |
return -1; |
| 43 |
} |
| 44 |
|
| 45 |
pos += (sizeof(eword_t) * 8); |
| 46 |
} |
| 47 |
return 0; |
| 48 |
} |