This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Don't issue array bound warnings on zero-length arrays
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Meador Inge <meadori at codesourcery dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 3 Sep 2013 17:45:18 +0200
- Subject: Re: [PATCH] Don't issue array bound warnings on zero-length arrays
- Authentication-results: sourceware.org; auth=none
- References: <1377875587-18004-1-git-send-email-meadori at codesourcery dot com> <CAFiYyc1Ny1ubzOQZC0NkpVTN5WxMONzgHLfbdkO5tBCLZXxrgA at mail dot gmail dot com> <522602E0 dot 3020502 at codesourcery dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Sep 03, 2013 at 10:40:16AM -0500, Meador Inge wrote:
> > And I fail to see why the testcase should
> > not warn. Clearly you have a definition of a here and it doesn't have
> > an element
> > so the access is out of bounds.
>
> Not always, 'size_a' can be zero and the warning is worded such that the out of
> bounds access always happens. In fact, changing the code to 'size_a = 0' still
> issues a warning.
How would that be different if you had that invalid access in a function
and never called the function, or called it only if (0) or similar?
We don't do reachability analysis, if any code we warn about can be
reachable from main, and still warn about invalid code, this is invalid
code, so it is IMHO just fine to warn about it.
Jakub