add a bitset_copy_into function and use it in belive.c to avoid assertion failures
authorMatthias Braun <matze@braunis.de>
Tue, 6 Apr 2010 14:37:06 +0000 (14:37 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 6 Apr 2010 14:37:06 +0000 (14:37 +0000)
[r27348]

ir/adt/bitset.h
ir/adt/raw_bitset.h
ir/be/belive.c

index 9f01046..931cc5c 100644 (file)
@@ -184,6 +184,12 @@ static inline void bitset_copy(bitset_t *tgt, const bitset_t *src)
        rbitset_copy(tgt->data, src->data, src->size);
 }
 
+static inline void bitset_copy_into(bitset_t *tgt, const bitset_t *src)
+{
+       assert(tgt->size >= src->size);
+       rbitset_copy_into(tgt->data, src->data, src->size);
+}
+
 /**
  * Find the next unset bit from a given bit.
  * @note Note that if pos is unset, pos is returned.
index 8764998..e38cc51 100644 (file)
@@ -587,4 +587,14 @@ static inline void rbitset_copy(unsigned *dst, const unsigned *src,
        memcpy(dst, src, BITSET_SIZE_BYTES(size));
 }
 
+static inline void rbitset_copy_into(unsigned *dst, const unsigned *src,
+                                     unsigned size)
+{
+       unsigned n         = BITSET_SIZE_ELEMS(size);
+       unsigned last_mask = rbitset_last_mask_(size);
+
+       memcpy(dst, src, (n-1) * (BITS_PER_ELEM/8));
+       dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
+}
+
 #endif
index 9977460..198c98e 100644 (file)
@@ -284,7 +284,7 @@ static void register_node(be_lv_t *lv, const ir_node *irn)
        unsigned idx = get_irn_idx(irn);
        if (idx >= bitset_size(lv->nodes)) {
                bitset_t *nw = bitset_malloc(2 * idx);
-               bitset_copy(nw, lv->nodes);
+               bitset_copy_into(nw, lv->nodes);
                bitset_free(lv->nodes);
                lv->nodes = nw;
        }