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

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 15 03:59:20 PST 2019


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


More information about the llvm-dev mailing list