Hi!
It seems pointers are sign extended to wider integers, is that intentional?
It certainly contradicts the comment in convert_to_integer:
switch (TREE_CODE (intype))
{
case POINTER_TYPE:
case REFERENCE_TYPE:
if (integer_zerop (expr))
return build_int_cst (type, 0);
/* Convert to an unsigned integer of the correct width first, and from
there widen/truncate to the required type. Some targets support the
coexistence of multiple valid pointer sizes, so fetch the one we need
from the type. */
expr = fold_build1 (CONVERT_EXPR,
lang_hooks.types.type_for_size
(TYPE_PRECISION (intype), 0),
expr);
return fold_convert (type, expr);
but the comment is newer than the sign extension.
void
foo (long long l)
{
if ((l >> (sizeof (void *) * __CHAR_BIT__ - 1)) == 1)
__builtin_puts ("pointers zero extend to wider integers");
else if ((l >> (sizeof (void *) * __CHAR_BIT__ - 1)) == -1)
__builtin_puts ("pointers sign extend to wider integers");
}
int
main (void)
{
int i;
if (sizeof (&i) < sizeof (long long))
foo ((long long) &i);
return 0;
}
Jakub