<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 17, 2010, at 10:42 AM, Andrew Haley wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 06/17/2010 06:19 PM, Jeffrey Yasskin wrote:<br><blockquote type="cite">On Thu, Jun 17, 2010 at 12:22 AM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite">On Wed, Jun 16, 2010 at 11:14 PM, Pierre C <<a href="mailto:lists@peufeu.com">lists@peufeu.com</a>> wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">There are essentially two ways to "solve" this issue: one is<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">type-based alias analysis, i.e. assuming "double" and "int" don't<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">alias; LLVM doesn't implement this at the moment.  The other is to<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">attempt to analyze the loop and prove that %indvar.i is never<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">negative; LLVM doesn't implement anything like this at the moment<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">either.<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">-Eli<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Actually I think it's much simpler than that...<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="http://llvm.org/releases/1.3/docs/AliasAnalysis.html#basic-aa">http://llvm.org/releases/1.3/docs/AliasAnalysis.html#basic-aa</a><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">it says says "Different fields of a structure do not alias."<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">This is the case here : we have two different fields of a struct however it<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">mistakenly thinks they alias.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Consider a case like the following:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">struct X { int a; int b[10]; };<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">int f(struct X* a) { a->b[-1] = 1; return a->a; }<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">This is technically illegal code, but various programs depend on<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">constructs like this working.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I don't know if it's illegal, but this is how libstdc++'s string<br></blockquote><blockquote type="cite">implementation finds its header data. std::string stores a pointer<br></blockquote><blockquote type="cite">directly to the character data (making subscripting slightly faster),<br></blockquote><blockquote type="cite">and then subtracts the size of the header when it needs to do any<br></blockquote><blockquote type="cite">bookkeeping.<br></blockquote><br>Character types are special: they can alias everything.  if this weren't<br>the case you couldn't write malloc().<br><br><blockquote type="cite">Do you have a reference to the standard that makes it undefined?<br></blockquote><br>Several places, but 6.3.2.3 of C99 is the most important: it lists all<br>the legal pointer conversions.<br></div></blockquote></div><br><div>The better reference is 6.5.6p7-8, about pointer addition:</div><div>  <span class="Apple-style-span" style="font-family: Times; font-size: 12px; ">For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.</span></div><div><span class="Apple-style-span" style="font-family: Times; ">  </span><span class="Apple-style-span" style="font-family: Times; font-size: 12px; ">If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.</span></div><div><font class="Apple-style-span" face="Times"><br></font></div><div><font class="Apple-style-span" face="Times"><span class="Apple-style-span" style="font-family: Helvetica; ">John.</span></font></div></body></html>