This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A question about detecting array bounds for case Warray-bounds-3.c
- From: Dirk Müller <dmueller at suse dot de>
- To: "Matthew Gretton-Dann" <matthew dot gretton-dann at arm dot com>, "rguenth at gcc dot gnu dot org" <rguenth at gcc dot gnu dot org>
- Cc: Jonathan Wakely <jwakely dot gcc at gmail dot com>, Jiangning Liu <Jiangning dot Liu at arm dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, "jakub at gcc dot gnu dot org" <jakub at gcc dot gnu dot org>
- Date: Wed, 28 Sep 2011 12:49:17 +0200
- Subject: Re: A question about detecting array bounds for case Warray-bounds-3.c
- References: <4e80264f.6ab8ec0a.78ce.ffffad1cSMTPIN_ADDED@mx.google.com> <CAH6eHdSNTOMpD1zEzNq+y=Y-V5cpePJdX9=5sHigZ+3rZQcBiw@mail.gmail.com> <4E804727.4000902@arm.com>
On Monday 26 September 2011, Matthew Gretton-Dann wrote:
> As far as I understand it -Warray-bounds should be emitting a warning
> for this case, but PR31227 seemed to be about removing these warnings.
>
> The PR comments do not explain why the array accesses are valid and I'm
> hoping someone can shed some light on the situation - what are we missing?
The fix for PR was when the address of an element beyond the array is taken,
but not actually dereferenced (used). For cases where the element is
dereferenced it should warn IMHO.
Note however that in this case it accesses an adjacent array of the same type
in memory, and it is arguable if it should give a warning there or not. I have
no strong opinion about this (I suspect that choosing for one variant gives
false positives, and the other false negatives). It seems fortify_source has a
similar problem, which is why they have added an option for it (1/2):
http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
I guess we need the same approach here.
Thanks,
Dirk