<div dir="ltr"><div dir="ltr"><div>> As with many things in the C and C++ specifications, this has very </div><div>> little relationship to real-world code.  The biggest example I've seen </div><div>> that violates this rule is the way that the FreeBSD kernel implements </div><div>> per-CPU storage, but in a fairly ad-hoc analysis of existing C/C++ code </div><div>> we found quite a few cases where subtraction occurred between objects.</div><div><br></div><div>Hello David,</div><div>If C programmer wants to get distance between two different objects, s/he can use (intptr_t)p - (intptr_t)q instead of p - q.</div><div>I believe this situation is similar to one adopting optimizations/analyses that exploit signed overflow / TBAA / etc.</div><div><br></div><div>Juneyoung Lee</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jan 15, 2019 at 11:59 AM David Chisnall via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 14/01/2019 20:55, Juneyoung Lee via llvm-dev wrote:<br>
> Correctness of psub is guaranteed by the specification of pointer <br>
> subtraction of C/C++.<br>
> When two pointers are subtracted, both shall point to elements of the <br>
> same array object, or one past the last element of the array object <br>
> (6.5.6.9).<br>
<br>
As with many things in the C and C++ specifications, this has very <br>
little relationship to real-world code.  The biggest example I've seen <br>
that violates this rule is the way that the FreeBSD kernel implements <br>
per-CPU storage, but in a fairly ad-hoc analysis of existing C/C++ code <br>
we found quite a few cases where subtraction occurred between objects.<br>
<br>
David<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><br></div><font size="1">Juneyoung Lee</font><div><font size="1">Software Foundation Lab, Seoul National University</font></div></div></div>