[PATCH] Warning for Out of bound access of Array of Structures/Unions not reported

Richard Smith richard at metafoo.co.uk
Mon Oct 14 21:26:11 PDT 2013


On Tue, Oct 8, 2013 at 6:17 PM, Jordan Rose <jordan_rose at apple.com> wrote:

>
>   Richard, I get the feeling that we should have just warned about the
> out-of-bounds array access before forming the MemberExpr. What do you think?
>
> http://llvm-reviews.chandlerc.com/D1580
>

I'm not really very happy with the way that CheckArrayAccess is distributed
across the code, with calls in a half-dozen places. I'd be surprised if
there aren't other ways to sneak an array access in that it won't see. In
fact, it failed to catch the very first thing I tried:

    int arr[10];
    int k = static_cast<int>(arr[12]);

I'd much prefer an approach that is correct by construction. How about:

When we build an array access, check the index against the bound. If it's
in bounds, ignore. If it's out of bounds, diagnose. If it's
one-past-the-end, add it to a DenseSet on Sema. When we build a unary * or
& operator, use that to maintain state on whether we're using the subscript
expression for its address or for its value. Likewise when we build a ?:
operator. And diagnose any at-bounds indexing when we get to the end of the
full-expression.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131014/8757dd36/attachment.html>


More information about the cfe-commits mailing list