This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: missing warnings with -Warray-bounds
- From: Martin Uecker <uecker at eecs dot berkeley dot edu>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc Mailing List <gcc at gcc dot gnu dot org>
- Date: Mon, 10 Nov 2014 01:22:24 -0800
- Subject: Re: missing warnings with -Warray-bounds
- Authentication-results: sourceware.org; auth=none
- References: <20141110002003 dot 186cc6d5 at lemur> <20141110082816 dot GE5026 at tucnak dot redhat dot com> <20141110005202 dot 7488e063 at lemur> <20141110090229 dot GF5026 at tucnak dot redhat dot com>
Jakub Jelinek <jakub@redhat.com>:
> On Mon, Nov 10, 2014 at 12:52:02AM -0800, Martin Uecker wrote:
> > Jakub Jelinek <jakub@redhat.com>:
...
> > The warning seems very useful to me and can easily be turned off.
> > Or one could add -W(no-)warn-struct-hack if really needed.
> >
> > Another odd case is:
> >
> > struct h0b {
> > int i;
> > int j[0];
> > int k;
> > };
> >
> > struct h0b* h0b = ...
> >
> > h0b->j[4] = 1;
>
> -fsanitize=undefined should catch this.
sanitize is not a replacment for a compile-time warning. The later
are much more useful.
> > > You haven't provided struct h definition,
> >
> > Sorry, this should have been sizeof(struct h3).
>
> In that case the code you've posted is valid, there should be no warnings or
> runtime error messages.
I meant malloc(sizeof(h3)) without the additional term.
But it is undefined behavior in any case, so I would expect
a compiler to give a warning.
Martin