This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] pointer to integer conversion.
- From: Iain Buclaw <ibuclaw at gdcproject dot org>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 23 Nov 2013 12:38:41 +0000
- Subject: Re: [PATCH] pointer to integer conversion.
- Authentication-results: sourceware.org; auth=none
- References: <CABOHX+cxn+h+Jr8Z+JE0XBdbOQ6hBtHTUX=0j=LFYyHoq199vg at mail dot gmail dot com> <m2zjovo0om dot fsf at linux-m68k dot org>
On 23 November 2013 10:46, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Iain Buclaw <ibuclaw@gdcproject.org> writes:
>
>> Currently, GCC is converting the expression to a signed integer
>> instead of an unsigned one. Does a test for the testsuite need to be
>> written for this?
>
> The C standard makes this implementation-defined, and GCC defines it
> like this (*Note (gcc) Arrays and pointers implementation::):
>
> A cast from pointer to integer discards most-significant bits if
> the pointer representation is larger than the integer type,
> sign-extends(1) if the pointer representation is smaller than the
> integer type, otherwise the bits are unchanged.
> ---------- Footnotes ----------
>
> (1) Future versions of GCC may zero-extend, or use a target-defined
> `ptr_extend' pattern. Do not rely on sign extension.
>
> Andreas.
>
OK, I've checked that document, and there's also a comment with it.
Apparently someone spotted this before.
@c ??? We've always claimed that pointers were unsigned entities.
@c Shouldn't we therefore be doing zero-extension? If so, the bug
@c is in convert_to_integer, where we call type_for_size and request
@c a signed integral type. On the other hand, it might be most useful
@c for the target if we extend according to POINTERS_EXTEND_UNSIGNED.
So where does this leave languages that say that pointer to integer
conversions are clearly defined?
In any case, the comment in convert_to_integer is - in my eyes - wrong.
Iain.