This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH:[darwin] fix load of a misaligned double word


Bradley Lucier writes:
 > 
 > On Dec 31, 2003, at 9:22 AM, Andrew Haley wrote:
 > 
 > > Regardless of whether this is an aliasing violation, constructing a
 > > misaligned pointer by use of pointer casts and then using that pointer
 > > is not well-defined.
 > 
 > The pointer is not misaligned.
 > 
 > >   (C99 Section 6.2.2.3, Pointers.)
 > 
 > I have a document n2794.pdf, which seems to be a draft of the standard, 
 > and can't find the section you're talking about.

I'm sorry, that's the section number in C90.  It's 6.3.2.3 in C99.

You're allowed to convert a pointer to a pointer of another type and
convert it back again.  But this

  (((int*)((___r1)-(1)))+1)

does arithmetic on an int* pointer and then this

  ((int)(((int*)((___r1)-(1)))+1))+(((((int)(8))<<2))<<(3-2)))

converts this pointer to an int and then this

  *(double*)(((int)(((int*)((___r1)-(1)))+1))+(((((int)(8))<<2))<<(3-2)))

converts to a double* and uses the result as an lvalue.

It's quite clear from the standard that all you may do with a pointer
is convert it to a sufficiently aligned pointer of a different type
and then convert it back.  You may not perform arithmetic on that
pointer in between.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]