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: Meador Inge <meadori at codesourcery dot com>
- To: Jakub Jelinek <jakub at redhat 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 11:01:17 -0500
- 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> <20130903154518 dot GI21876 at tucnak dot zalov dot cz>
On 09/03/2013 10:45 AM, Jakub Jelinek wrote:
> 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.
True. Perhaps I am getting too caught up in the wording. I thought we
typically use "may" for warnings that aren't definitive, but in this case
we use "is" (instead of something like "may be"):
warning: array subscript is above array bounds [-Warray-bounds]
--
Meador Inge
CodeSourcery / Mentor Embedded