X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Fbitset.h;h=9ae16372b73ff483b755c33563e7b8fc9254636a;hb=d2dc2564b47d9c113d7e6e598574e9733627fcca;hp=ad920a840d74df018996856faaa524ba3ce5eb05;hpb=07d33d22fcc65609a2c31c516604bda6e615bf72;p=libfirm diff --git a/ir/adt/bitset.h b/ir/adt/bitset.h index ad920a840..9ae16372b 100644 --- a/ir/adt/bitset.h +++ b/ir/adt/bitset.h @@ -16,6 +16,12 @@ #include "firm_config.h" #include "bitfiddle.h" +#ifdef _WIN32 +#include +#else +#include +#endif + typedef unsigned int bitset_pos_t; #include "bitset_std.h" @@ -60,7 +66,7 @@ static INLINE bitset_t *_bitset_prepare(void *area, bitset_pos_t size) bitset_t *ptr = area; memset(area, 0, _bitset_overall_size(sizeof(bitset_t), size)); ptr->units = _bitset_units(size); - ptr->size = size; + ptr->size = size; ptr->data = _bitset_data_ptr(area, sizeof(bitset_t), size); return ptr; } @@ -266,8 +272,9 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, bitset_pos_t pos, int set) { bitset_pos_t unit_number = pos / BS_UNIT_SIZE_BITS; + bitset_pos_t res; - if(unit_number >= bs->units) + if(pos >= bs->size) return -1; { @@ -289,8 +296,10 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, _bitset_inside_ntz_value((set ? curr_unit : ~curr_unit) & ~in_unit_mask); /* If there is a bit set in the current unit, exit. */ - if(next_in_this_unit < BS_UNIT_SIZE_BITS) - return next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS; + if (next_in_this_unit < BS_UNIT_SIZE_BITS) { + res = next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS; + return res < bs->size ? res : -1; + } /* Else search for set bits in the next units. */ else { @@ -300,8 +309,10 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, bitset_pos_t first_set = _bitset_inside_ntz_value(set ? data : ~data); - if(first_set < BS_UNIT_SIZE_BITS) - return first_set + i * BS_UNIT_SIZE_BITS; + if (first_set < BS_UNIT_SIZE_BITS) { + res = first_set + i * BS_UNIT_SIZE_BITS; + return res < bs->size ? res : -1; + } } } }