This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH:[darwin] fix load of a misaligned double word
Bradley Lucier writes:
>
> On Dec 31, 2003, at 1:08 PM, Andrew Haley wrote:
>
> > Bradley Lucier writes:
> >>
> >> So it comes down to a quality of implementation question. You're
> >> saying that my "implementation defined" code is clearly wrong, and
> >> everyone else's "implementation defined" conversion between pointers
> >> and ints is OK; I have yet to be convinced.
> >
> > I don't understand your point. If it is true, as I maintain, that
> > performing arithmetic on an int* and then using the resulting pointer
> > as a double* is undefined, then the code you present is undefined.
>
> Part 7 says
>
> > 7 A pointer to an object or incomplete type may be converted to a
> > pointer to a different object or incomplete type. If the resulting
> > pointer is not correctly aligned 57) for the pointed-to type, the
> > behavior is undefined. Otherwise, when converted back again, the
> > result shall compare equal to the original pointer. When a pointer to
> > an object is converted to a pointer to a character type, the result
> > points to the lowest addressed byte of the object. Successive
> > increments of the result, up to the size of the object, yield pointers
> > to the remaining bytes of the object.
>
> so looking at my code.
>
> int -> int * is valid, though implementation defined
>
> addition of 1 to int * is valid
> int * -> int is valid, though implementation defined
>
> int -> double * is valid, though implementation defined
My reading of the standard is that the conversion from int -> double *
is only valid if that int was the result of a conversion from a
pointer that was a double*.
> Even if I went directly from int * -> double *, it would be undefined
> only if it is not correctly aligned, and I know that it *is* correctly
> aligned.
> > That isn't a quality of implementation issue: the code in question
> > simply doesn't mean anything.
>
> Parts 5 and 6 say that integers may be converted to and from pointers,
> and the results are implementation defined. Full stop.
What it does not say, however, is that you may convert a pointer from
a double* to an int*, do arithmetic on that int* pointer, and then
convert it back to a double*. It merely says that a double* pointer
may be converted to some other pointer and then back to a double*
pointer.
Andrew.