On Thu, Feb 18, 2021 at 09:24:28AM -0700, Martin Sebor via Gcc-patches wrote:
> > Consider a different (GNU C, in C++ struct S has non-zero size) testcase:
> > void f (void*);
> >
> > void g (int n)
> > {
> > struct S {} a[n];
> > ((int*)a)[0] = 0;
> > f (a);
> > }
> > yyy.c:6:12: warning: array subscript 0 is outside array bounds of ‘struct
> > S[<Ucc60>]’ [-Warray-bounds]
> > 6 | ((int*)a)[0] = 0;
> > | ~~~~~~~~~^~~
> > yyy.c:5:15: note: while referencing ‘a’
> > 5 | struct S {} a[n];
> > | ^
> > I bet that means you are really complaining about the VLA bound rather than
> > the [0] bound even in the first case, because the wording is otherwise the
> > same. And for g (154) the array subscript 0 is certainly not a problem,
> > so the warning would need to be worded differently in that case.
>
> I'm not sure I follow what you're saying here either. The vrp1 dump
> has this:
>
> void g (int n)
> {
> struct S a[0:D.1951];
>
> <bb 2> [local count: 1073741824]:
> MEM[(int *)&a] = 0;
> f (&a);
> a ={v} {CLOBBER};
> return;
>
> }
>
> The size of the VLA is zero regardless of its bound and accessing
> it is invalid so the warning is expected.
Yes, some warning, but not the one you are giving, that is nonsensical.
Array subscript 0 is not outside of array bounds of struct S[n], a[anything]
will still be zero sized and will not be problematic.
> VLAs of zero-lengthg arrays are without a doubt rare, pathological
> cases. We could special case the warning for them and print
> a different message but I see very little value in complicating
> the code just for them. Do you consider this special casing
> a requirement for approving the fix for the ICE?
Yes.
Jakub