On 23 November 2013 10:46, Andreas Schwab <sch...@linux-m68k.org> wrote: > Iain Buclaw <ibuc...@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.