PATCH: change splay_tree_key & splay_tree_value types to void*

Greg McGary greg@mcgary.org
Tue Aug 29 21:17:00 GMT 2000


Mark Mitchell <mark@codesourcery.com> writes:

> >>>>> "Jeffrey" == Jeffrey A Law <law@cygnus.com> writes:
> 
>     Jeffrey>   In message < 200008252105.OAA24749@kayak.mcgary.org >you
>     Jeffrey> write:
>     >> Splay trees with string keys & values need to store bounds, so
>     >> a `long' doesn't do the job.  I changed `long' to `void*', but
>     >> that might be too naive if GCC supports architectures for which
>     >> sizeof (long) > sizeof (void*).  If we need to handle that,
>     >> then I guess we should make these types unions.
> 
> Since there would be problems for bounded pointer users if casts from
> pointers to and from integers don't work

They do work, but they lose information.  Cast from pointer to integer
and the bounds are discarded.  Cast from integer to pointer and gcc
attaches the bounds [0..0), which are going to cause failure as soon
as you try and dereference it.  Note that gcc does take special care
to propagate the bounds through pointer-bit-fiddling expressions where
we temporarily cast a pointer to int, round the pointer up or down to
an alignment boundary then cast it back to a pointer.

> ... I'm assuming that you're
> just trying to maximize the use of bounded pointers in GCC itself,
> right?  

Yes.

> If that's the case, I'd suggest we just leave splay trees alone, and
> accept the reduced checking.

It's not so easy.  Pass integers to strcmp and they're promoted to
bounded pointers--that part works--but the bounds that are attached in
this case are [0..0), and the checks inside strcmp fail.  I'm loath to
attach maximally permissive bounds of [0, ~0) to integers in the
int->BP promotion because that seriously undermines the ability of BPs
to catch bugs.

Please accept making the types conditional on __BOUNDED_POINTERS__
(void* for BPs, and keeping unsigned long for non-BP) as in my most
recent patch.

Greg


More information about the Gcc-patches mailing list