http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52415

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-02-28 
12:15:53 UTC ---
(In reply to comment #2)
> > On the tree level nothing guarantees that 'p' is properly aligned.
> 
> This is a digression, but what about C99 (Committee Draft -- April 12, 2011)
> 6.3.2.3p7:
> 
> "A pointer to an object type may be converted to a pointer to a different
> object type. If the resulting pointer is not correctly aligned for the
> referenced type, the behavior is undefined."
> 
> Doesn't that guarantee that p is properly aligned? If not, how can I assert
> that p *is* properly aligned, so the compiler can turn the memcpy into an
> aligned load? Thanks.

Well, not exactly.  The GIMPLE IL does not map 1:1 to the C99 spec (after
all it has to support other languages besides C).  There is no convenient
way for a frontend to tell the middle-end that 'p' is properly aligned
for a float.  Note that the situation is complicated by the fact that,
as GCC extension, you can create a misaligned variant

typedef float my_float __attribute__((aligned(1)));

int f(my_float *p) {
  int i;
  __builtin_memcpy(&i, p, sizeof i);
  return i;
}

which needs to be handled correctly as well (we don't on STRICT_ALIGNMENT
targets).  The my_float * case is of course not covered by C99.

Reply via email to