[cfe-dev] -Warray-bounds false positive?

Kaelyn Uhrain rikka at google.com
Thu Aug 25 15:26:15 PDT 2011


Jordy et al,

The check *should* be accounting for the array being cast to char*... not
sure why it isn't (and in the middle of trying to refactor
ActOnFunctionDeclarator). When the bug is filed you can assign it it me, as
I've already done a lot of work on improving -Warray-bounds and would like
to know/dig into why the false positive is triggering.

Cheers,
Kaelyn

On Thu, Aug 25, 2011 at 3:12 PM, Ted Kremenek <kremenek at apple.com> wrote:

> Ah, you're right.  We should adjust the array size in the warning based on
> the pointer type being accessed.
>
> On Aug 25, 2011, at 3:01 PM, Jordy Rose wrote:
>
> > But it's been casted to char *. This is equivalent to this code:
> >
> > double foo[4096];
> > char *bar = (char *)foo;
> > bar[sizeof(foo)-1] = '\0';
> >
> > I mean, it's probably a bad idea, but it's not an out-of-bounds error.
> >
> >
> > On Aug 25, 2011, at 14:59, Ted Kremenek wrote:
> >
> >> No, the warning is legit.  sizeof() returns the size in bytes, not
> elements.  This is an array of doubles.
> >>
> >> On Aug 25, 2011, at 2:22 PM, Jordy Rose wrote:
> >>
> >>>
> >>> On Aug 25, 2011, at 14:00, Sean McBride wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I'm not enough of a language lawyer to be 100% sure, but:
> >>>>
> >>>> -----
> >>>> int main (void)
> >>>> {
> >>>>    double foo[4096];
> >>>>    ((char *)(foo))[(sizeof(foo)-1)] = '\0';
> >>>>
> >>>>    return 0;
> >>>> }
> >>>> -----
> >>>>
> >>>> test.cp:4:12: warning: array index of '32767' indexes past the end of
> an array (that contains 4096 elements) [-Warray-bounds]
> >>>>     ((char *)(foo))[(sizeof(foo)-1)] = '\0';
> >>>>               ^      ~~~~~~~~~~~~~
> >>>>
> >>>> Is a false positive, right?
> >>>
> >>> Yes. File a bug? :-)
> >>>
> >>>
> >>> _______________________________________________
> >>> cfe-dev mailing list
> >>> cfe-dev at cs.uiuc.edu
> >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >>
> >
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110825/df1488f1/attachment.html>


More information about the cfe-dev mailing list