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]

Re: Patch: convenience routines for hashtab.c



  The routine in hashtab.c

  /* Returns a hash code for P.  */

  static hashval_t
  hash_pointer (p)
       const void *p;
  {
    return (hashval_t) p;
  }

  on the alpha converts a 64-bit pointer to a 32-bit int, and so generates
  the warning:

  ../../../libiberty/hashtab.c: In function `hash_pointer':
  ../../../libiberty/hashtab.c:107: warning: cast from pointer to integer of different size

  Was it intended to throw away the top 32 bits of the pointer?  If so,
  can we silence this warning somehow?  (Often, this warning indicates
  real problems on the alpha, so I'd like to get rid of any bogus warnings
  if possible.)

Now we see why we wanted hashval_t to be a typedef.  I was thinking of
precisely a situation like this.

In this case, there is no error.  Most of the variability in a pointer
is in the low order bits anyhow, so throwing away the high order bits
probably results in just as a good a hash function.  So, we could just
silence the warning.

Alternatively, there's no harm in having the hash value be a larger
type.  The right size is probably exactly the size of a pointer;
that's a good size for lots of "generic" data types.  (It would be
disadvantageous to use 64-bit hashes on 32-bit machines, though.)

A patch to do either would be appreciated.  Thanks!

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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