Created attachment 41274 [details]
GCC should treat zero length arrays like C99 flexible arrays when they are
at the end of a structure. I.e. recognize that accesses to that array may
go beyond the end of the structure. GCC has been treating zero length
arrays and flexible arrays differently since at least 5.0.
This was found on aarch64 but the bug is not platform specific. A test case
is attached, it cannot be run but if compiled for aarch64 with
-O2 -fno-strict-aliasing and either -UFLEX or -DFLEX you can see the
different code. In the -UFLEX case it generates a load/load/store/store
sequence and in the -DFLEX case it generates load/store/load/store for
the code in the main loop.
Date: Thu Apr 27 12:34:45 2017
New Revision: 247327
2017-04-27 Richard Biener <firstname.lastname@example.org>
* emit-rtl.c (set_mem_attributes_minus_bitpos): When
stripping ARRAY_REFs from MEM_EXPR make sure we're not
keeping a reference to a trailing array.
Fixed on trunk sofar.
Fixed on all still maintained branches.