This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][RFC] Pointer to integer conversion
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 Oct 2005 21:37:18 +0200 (CEST)
- Subject: [PATCH][RFC] Pointer to integer conversion
After some discussion about the implementation defined conversion
of a pointer to a larger integer I was pointed to
convert.c:convert_to_integer which does
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. */
expr = fold_build1 (CONVERT_EXPR,
lang_hooks.types.type_for_size (POINTER_SIZE,
0),
expr);
return fold_build1 (NOP_EXPR, type, expr);
note, that the comment doesn't match the code, as we are requesting
a signed integer from type_for_size (which in turn matches the
implement-c.texi documentation which says our pointers are signed).
I really question if the middle-end is supposed to make any such
decision here - either the frontend or the backend should decide
if pointers are signed or unsigned. So what about the patch below?
check-gcc tested.
Richard.
Index: convert.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/convert.c,v
retrieving revision 1.70
diff -c -3 -p -r1.70 convert.c
*** convert.c 5 Oct 2005 17:29:41 -0000 1.70
--- convert.c 10 Oct 2005 19:32:02 -0000
*************** convert_to_integer (tree type, tree expr
*** 386,392 ****
! /* Convert to an unsigned integer of the correct width first,
and from there widen/truncate to the required type. */
expr = fold_build1 (CONVERT_EXPR,
! lang_hooks.types.type_for_size (POINTER_SIZE, 0),
expr);
return fold_build1 (NOP_EXPR, type, expr);
--- 386,393 ----
! /* Convert to an integer of the correct width and signedness first,
and from there widen/truncate to the required type. */
expr = fold_build1 (CONVERT_EXPR,
! lang_hooks.types.type_for_size (POINTER_SIZE,
! TYPE_UNSIGNED (intype)),
expr);
return fold_build1 (NOP_EXPR, type, expr);