This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Alias analysis and zero-sized arrays vs. flexible arrays
- From: Steve Ellcey <sellcey at cavium dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Tue, 25 Apr 2017 11:03:20 -0700
- Subject: Re: Alias analysis and zero-sized arrays vs. flexible arrays
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=cavium.com;
- References: <201704242306.v3ON6iSI022843@sellcey-dt.caveonetworks.com> <CAFiYyc1AWazAvuD7yhS8QmS1JefKvQJzoGme-rEor3O1K0ngRw@mail.gmail.com>
- Reply-to: sellcey at cavium dot com
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On Tue, 2017-04-25 at 12:53 +0200, Richard Biener wrote:
> > int foo() {
> > int i,j;
> > for (i = 0; i < m; i++) {
> > a->o[i] = sizeof(*a);
> > b = ((struct r *)(((char *)a) + a->o[a->n]));
> > for (j = 0; j < 10; j++) {
> > b->slot[j].b = 0;
> in case b->slot[j].b aliases a->o[i] or a->o[a->n]
> you invoke undefined behavior becuase you violate
> strict aliasing rules. I don't know why there's a
> difference between -DFLEX and -UFLEX but your
> code is buggy even if it works in one case.
>
> Richard.
Should this work if I use -fno-strict-alias? Even with that option I
get different code with a zero-sized array vs. a flexible array.
I have a patch to get_ref_base_and_extent that changes the behaviour
for zero-length arrays and I will submit it after I have tested it.
Steve Ellcey
sellcey@cavium.com