Bug 80533 - Alias analysis of zero length array does not recognize accesses beyond end of array
Summary: Alias analysis of zero length array does not recognize accesses beyond end of...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-04-26 19:07 UTC by Steve Ellcey
Modified: 2020-02-14 09:48 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 5.4.0, 6.3.0, 7.1.0, 7.5.0
Last reconfirmed: 2017-04-27 00:00:00


Attachments
Test case (249 bytes, text/plain)
2017-04-26 19:07 UTC, Steve Ellcey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Ellcey 2017-04-26 19:07:20 UTC
Created attachment 41274 [details]
Test case

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.

See also:

https://gcc.gnu.org/ml/gcc/2017-04/msg00118.html
https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01257.html
Comment 1 Richard Biener 2017-04-27 07:55:09 UTC
Mine.
Comment 2 Richard Biener 2017-04-27 12:35:16 UTC
Author: rguenth
Date: Thu Apr 27 12:34:45 2017
New Revision: 247327

URL: https://gcc.gnu.org/viewcvs?rev=247327&root=gcc&view=rev
Log:
2017-04-27  Richard Biener  <rguenther@suse.de>

	PR middle-end/80533
	* 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.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/emit-rtl.c
Comment 3 Richard Biener 2017-04-27 12:59:11 UTC
Fixed on trunk sofar.
Comment 4 Richard Biener 2020-02-14 09:48:33 UTC
Fixed on all still maintained branches.