[Bug tree-optimization/50417] regression: memcpy with known alignment

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Tue Jul 12 13:01:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50417

--- Comment #26 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 12 Jul 2016, npl at chello dot at wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50417
> 
> --- Comment #25 from npl at chello dot at ---
> Yes, that works fine. I just meant to say it needs more work than casting to a
> type with less alignment, and unless explicitly marked with this pragma you can
> expect a compiler to access like the (deduced) type was properly aligned.

sth like

typedef int acc __attribute__((may_alias, aligned(1)));

and an actual access like

  *(acc *)p;

works as well (type punning allowed via may_alias, alignment adjusted
to 1 byte).

Of course that's not portable.

Portable is to use memcpy which irrespective of the type of the
pointer has to assume an unaligned access.


More information about the Gcc-bugs mailing list