OSDN Git Service

* config/darwin.c (machopic_symbol_defined_p): In addition to
[pf3gnuchains/gcc-fork.git] / gcc / sbitmap.c
index 508eca3..dfd7645 100644 (file)
@@ -41,7 +41,7 @@ sbitmap_alloc (unsigned int n_elms)
   bytes = size * sizeof (SBITMAP_ELT_TYPE);
   amt = (sizeof (struct simple_bitmap_def)
         + bytes - sizeof (SBITMAP_ELT_TYPE));
-  bmap = (sbitmap) xmalloc (amt);
+  bmap = xmalloc (amt);
   bmap->n_bits = n_elms;
   bmap->size = size;
   bmap->bytes = bytes;
@@ -64,7 +64,7 @@ sbitmap_resize (sbitmap bmap, unsigned int n_elms, int def)
     {
       amt = (sizeof (struct simple_bitmap_def)
            + bytes - sizeof (SBITMAP_ELT_TYPE));
-      bmap = (sbitmap) xrealloc (bmap, amt);
+      bmap = xrealloc (bmap, amt);
     }
 
   if (n_elms > bmap->n_bits)
@@ -103,6 +103,32 @@ sbitmap_resize (sbitmap bmap, unsigned int n_elms, int def)
   return bmap;
 }
 
+/* Re-allocate a simple bitmap of N_ELMS bits. New storage is uninitialized.   */
+
+sbitmap
+sbitmap_realloc (sbitmap src, unsigned int n_elms)
+{
+  unsigned int bytes, size, amt;
+  sbitmap bmap;
+
+  size = SBITMAP_SET_SIZE (n_elms);
+  bytes = size * sizeof (SBITMAP_ELT_TYPE);
+  amt = (sizeof (struct simple_bitmap_def)
+        + bytes - sizeof (SBITMAP_ELT_TYPE));
+
+  if (src->bytes  >= bytes)
+    {
+      src->n_bits = n_elms;
+      return src;
+    }
+
+  bmap = (sbitmap) xrealloc (src, amt);
+  bmap->n_bits = n_elms;
+  bmap->size = size;
+  bmap->bytes = bytes;
+  return bmap;
+}
+
 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits.  */
 
 sbitmap *
@@ -130,7 +156,7 @@ sbitmap_vector_alloc (unsigned int n_vecs, unsigned int n_elms)
   }
 
   amt = vector_bytes + (n_vecs * elm_bytes);
-  bitmap_vector = (sbitmap *) xmalloc (amt);
+  bitmap_vector = xmalloc (amt);
 
   for (i = 0, offset = vector_bytes; i < n_vecs; i++, offset += elm_bytes)
     {
@@ -250,9 +276,16 @@ sbitmap_not (sbitmap dst, sbitmap src)
   unsigned int i, n = dst->size;
   sbitmap_ptr dstp = dst->elms;
   sbitmap_ptr srcp = src->elms;
+  unsigned int last_bit;
 
   for (i = 0; i < n; i++)
     *dstp++ = ~*srcp++;
+
+  /* Zero all bits past n_bits, by ANDing dst with sbitmap_ones.  */
+  last_bit = src->n_bits % SBITMAP_ELT_BITS;
+  if (last_bit)
+    dst->elms[n-1] = dst->elms[n-1]
+      & ((SBITMAP_ELT_TYPE)-1 >> (SBITMAP_ELT_BITS - last_bit));
 }
 
 /* Set the bits in DST to be the difference between the bits
@@ -298,7 +331,7 @@ sbitmap_a_and_b_cg (sbitmap dst, sbitmap a, sbitmap b)
   for (i = 0; i < n; i++)
     {
       SBITMAP_ELT_TYPE tmp = *ap++ & *bp++;
-      changed = *dstp ^ tmp;
+      changed |= *dstp ^ tmp;
       *dstp++ = tmp;
     }
 
@@ -332,7 +365,7 @@ sbitmap_a_xor_b_cg (sbitmap dst, sbitmap a, sbitmap b)
   for (i = 0; i < n; i++)
     {
       SBITMAP_ELT_TYPE tmp = *ap++ ^ *bp++;
-      changed = *dstp ^ tmp;
+      changed |= *dstp ^ tmp;
       *dstp++ = tmp;
     }
 
@@ -366,7 +399,7 @@ sbitmap_a_or_b_cg (sbitmap dst, sbitmap a, sbitmap b)
   for (i = 0; i < n; i++)
     {
       SBITMAP_ELT_TYPE tmp = *ap++ | *bp++;
-      changed = *dstp ^ tmp;
+      changed |= *dstp ^ tmp;
       *dstp++ = tmp;
     }