<br><br><div class="gmail_quote">On Tue, Jan 8, 2013 at 7:29 PM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="im">On 8 January 2013 16:53, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote">
<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>I'm not sure what you mean by "fix user's stupidity" here - could you clarify?<br></div></blockquote><div><br></div></div><div>Buffer overrun on foo[20] and relying on it for bar[20].</div>
<div><br></div><div>It might not even be an error to access foo[50] even though foo only has 20 elements (via pointer indirection rules), but it's user error to do so, and if the standard allows that (I'm yet to find the paragraph), then the compiler has no right to "fix" it. If it's undefined, than LTO is completely right and nothing should be done.</div>
<div><br></div></div></div></div></blockquote><div><br>I do believe it's undefined.<br><br>§5.2.1 Subscripting [expr.sub]<br><br>1/ A postfix expression followed by an expression in square brackets is a postfix expression. One of the expressions<br>
shall have the type “pointer to T” and the other shall have unscoped enumeration or integral type.<br>The result is an lvalue of type “T.” The type “T” shall be a completely-defined object type.62 The expression<br>E1[E2] is identical (by definition) to *((E1)+(E2))<br>
<br><br>§5.7 Additive operators [expr.add]<br><br>5/ When an expression that has integral type is added to or subtracted from a pointer, the result has the type<br>of the pointer operand. If the pointer operand points to an element of an array object, <b>**and the array is<br>
large enough**</b>, the result points to an element offset from the original element such that the difference of<br>the subscripts of the resulting and original array elements equals the integral expression. [...]<br><br>
<br>There is later (in §8.3.4 Arrays) a special case access out of bounds within a multi-dimensional array; however that is not our concern here.<br><br><br>Obviously, a warning, if possible, could be nice; but in general I am afraid this is more the domain of static analysis as it requires "guessing" the bounds of the loop. It might have been caught with ubsan though (I think there is an out-of-bounds checker).<br>
<br>-- Matthieu <br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>The "stupidity" part is to rely on undefined behaviour. Mind you, the stupidity in this case was mine. I removed functions from Livermore that I though were harmless, and added a few arrays to be initialized by others and haven't checked that the ranges were dynamic.</div>
<div><br></div><div>cheers,<br></div><div>--renato</div></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br>