<div dir="ltr">On Tue, Oct 8, 2013 at 6:17 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
  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?<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D1580" target="_blank">http://llvm-reviews.chandlerc.com/D1580</a><br>
</blockquote></div><br></div><div class="gmail_extra">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:</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">    int arr[10];</div><div class="gmail_extra">    int k = static_cast<int>(arr[12]);</div><div class="gmail_extra"><br></div><div class="gmail_extra">I'd much prefer an approach that is correct by construction. How about:</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
</div>