https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752
--- Comment #62 from rguenther at suse dot de <rguenther at suse dot de> --- On Tue, 4 Aug 2020, tavianator at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752 > > Tavian Barnes <tavianator at gmail dot com> changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |tavianator at gmail dot com > > --- Comment #61 from Tavian Barnes <tavianator at gmail dot com> --- > (In reply to rguent...@suse.de from comment #44) > > The other (unfortunate) thing is that in GCC pointer subtraction > > is always performed on integers, thus for the C source code > > > > int idx = ptr1 - ptr2; > > > > we internally have sth like > > > > int idx = ((long)ptr1 - (long)ptr2) / 4; > > > > so you can't really treat pointers as "escaped" here without loss. > > It seems possible to distinguish between ptr-to-int casts that actually occur > in the source, from ptr-to-int casts that are generated for other reasons by > the compiler. Note meanwhile there is a special opcode for pointer subtraction so we see (ptr1 p- ptr2) / 4 with 'p-' being POINTER_DIFF_EXPR yielding a signed integer result denoting the byte offset between both pointers.