diff options
Diffstat (limited to 'gcc/sbitmap.c')
-rw-r--r-- | gcc/sbitmap.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/gcc/sbitmap.c b/gcc/sbitmap.c index e581000e877..170d87df839 100644 --- a/gcc/sbitmap.c +++ b/gcc/sbitmap.c @@ -218,13 +218,26 @@ void sbitmap_difference (dst, a, b) sbitmap dst, a, b; { - unsigned int i, n = dst->size; + unsigned int i, dst_size = dst->size; + unsigned int min_size = dst->size; sbitmap_ptr dstp = dst->elms; sbitmap_ptr ap = a->elms; sbitmap_ptr bp = b->elms; - - for (i = 0; i < n; i++) - *dstp++ = *ap++ & ~*bp++; + + /* A should be at least as large as DEST, to have a defined source. */ + if (a->size < dst_size) + abort (); + /* If minuend is smaller, we simply pretend it to be zero bits, i.e. + only copy the subtrahend into dest. */ + if (b->size < min_size) + min_size = b->size; + for (i = 0; i < min_size; i++) + *dstp++ = *ap++ & (~*bp++); + /* Now fill the rest of dest from A, if B was too short. + This makes sense only when destination and A differ. */ + if (dst != a && i != dst_size) + for (; i < dst_size; i++) + *dstp++ = *ap++; } /* Set DST to be (A and B). @@ -658,27 +671,35 @@ dump_sbitmap (file, bmap) } void -debug_sbitmap (bmap) +dump_sbitmap_file (file, bmap) + FILE *file; sbitmap bmap; { unsigned int i, pos; - fprintf (stderr, "n_bits = %d, set = {", bmap->n_bits); + fprintf (file, "n_bits = %d, set = {", bmap->n_bits); for (pos = 30, i = 0; i < bmap->n_bits; i++) if (TEST_BIT (bmap, i)) { if (pos > 70) { - fprintf (stderr, "\n"); + fprintf (file, "\n "); pos = 0; } - fprintf (stderr, "%d ", i); - pos += 1 + (i >= 10) + (i >= 100); + fprintf (file, "%d ", i); + pos += 2 + (i >= 10) + (i >= 100) + (i >= 1000); } - fprintf (stderr, "}\n"); + fprintf (file, "}\n"); +} + +void +debug_sbitmap (bmap) + sbitmap bmap; +{ + dump_sbitmap_file (stderr, bmap); } void |