[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Conversion of pointers to integers and vice versa; pointer tagging



Implementations of languages with garbage collection and dynamic
typing often employ the concept of tagged pointers. Unused bits of a
pointer representation are used to distinguish between pointers to
different types or between pointers and immediate values.

Implementing such a language with libgccjit raises a couple of questions:

1) libgccjit has currently only a limited set of type-casting
expressions. In particular, there is no type-casting expression
between an integer type (e.g. uintptr_t) and a pointer type defined.

Are there technical reasons for that or is that just an area where
libgccjit still has to be complemented?

I guess, a workaround could be to use union types à la

union {
  uintptr_t i;
  void *p;
}

everywhere.

2) For pointer tagging, one needs to know which bits in the integer
representation of a pointer are unused. Does GCC make the guarantee
that on all supported platforms a pointer aligned on a 2^d-byte
boundary has its lower d bits zeroed? Is pointer arithmetic compatible
with the arithmetic on the underlying integer type? (I know that ISO C
does not make these guarantees, but we are talking about a particular
implementation here.)

3) One may want to use bit fields when implementing tags. The
documentation for libgccjit seems to be silent on bit fields in
structures. Is this feature on the TODO list?

Thanks!

-- Marc

P.S.: A Happy New Year to everyone!