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
On April 25, 2017 8:03:20 PM GMT+02:00, Steve Ellcey <sellcey@cavium.com> wrote:
>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?
Yes.
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.
OK. I briefly skimmed get_ref_base_and_extent and didn't see where it would make a difference. Your patch should make that obvious (and allow for a much shorter testcase).
Richard.
>Steve Ellcey
>sellcey@cavium.com