This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] sbitmap.h: Fix a fallout from my previous patch.


Hi,

Attached is a patch to fix a fallout from my previous patch.

The problem is that BIT_NUM in sbitmap_iterator, which I just introduced, is sometimes treated as "the current bit index" and sometimes treated as "the current bit index modulo SBITMAP_ELT_BITS". Obviously I need to be consistent here.

The patch fixes the problem by treating BIT_NUM as "the current bit index" with no modulo.

A latent bug that might happen is as follows. Assume

o SBITMAP_ELT_BITS is 32,

o MIN given to the iterator is 40, and

o bit 40 is set in the given instance of sbitmap,

then the iterator would store 8 in the user variable N given to the iterator.

This bug does not do any harm now because currently the only nonzero MIN in the gcc source code is 1, in tree-ssa-live.c.

Tested on x86_64-pc-linux-gnu. Committed as obvious.

Kazu Hirata
2005-06-07  Kazu Hirata  <kazu@codesourcery.com>

	* sbitmap.h (sbitmap_iter_init): Consistently treat bit_num as
	the current bit index with no modulo.

Index: sbitmap.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/sbitmap.h,v
retrieving revision 1.27
diff -u -d -p -r1.27 sbitmap.h
--- sbitmap.h	7 Jun 2005 14:30:20 -0000	1.27
+++ sbitmap.h	7 Jun 2005 14:56:49 -0000
@@ -66,7 +66,7 @@ typedef struct {
   /* The current word index.  */
   unsigned int word_num;
 
-  /* The current bit index.  */
+  /* The current bit index (not modulo SBITMAP_ELT_BITS).  */
   unsigned int bit_num;
 
   /* The words currently visited.  */
@@ -80,14 +80,15 @@ static inline void
 sbitmap_iter_init (sbitmap_iterator *i, sbitmap bmp, unsigned int min)
 {
   i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
-  i->bit_num = min % (unsigned int) SBITMAP_ELT_BITS;
+  i->bit_num = min;
   i->size = bmp->size;
   i->ptr = bmp->elms;
 
   if (i->word_num >= i->size)
     i->word = 0;
   else
-    i->word = i->ptr[i->word_num] >> i->bit_num;
+    i->word = (i->ptr[i->word_num]
+	       >> (i->bit_num % (unsigned int) SBITMAP_ELT_BITS));
 }
 
 /* Return true if we have more bits to visit, in which case *N is set

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]