[llvm-dev] Reducing the number of ptrtoint/inttoptrs that are generated by LLVM

Juneyoung Lee via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 15 08:26:58 PST 2019


> As with many things in the C and C++ specifications, this has very
> little relationship to real-world code.  The biggest example I've seen
> that violates this rule is the way that the FreeBSD kernel implements
> per-CPU storage, but in a fairly ad-hoc analysis of existing C/C++ code
> we found quite a few cases where subtraction occurred between objects.

Hello David,
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.
I believe this situation is similar to one adopting optimizations/analyses
that exploit signed overflow / TBAA / etc.

Juneyoung Lee

On Tue, Jan 15, 2019 at 11:59 AM David Chisnall via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> On 14/01/2019 20:55, Juneyoung Lee via llvm-dev wrote:
> > Correctness of psub is guaranteed by the specification of pointer
> > subtraction of C/C++.
> > When two pointers are subtracted, both shall point to elements of the
> > same array object, or one past the last element of the array object
> > (6.5.6.9).
>
> As with many things in the C and C++ specifications, this has very
> little relationship to real-world code.  The biggest example I've seen
> that violates this rule is the way that the FreeBSD kernel implements
> per-CPU storage, but in a fairly ad-hoc analysis of existing C/C++ code
> we found quite a few cases where subtraction occurred between objects.
>
> David
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


-- 

Juneyoung Lee
Software Foundation Lab, Seoul National University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190115/af240b11/attachment.html>


More information about the llvm-dev mailing list