This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/81801] [PATCH] Difference of two pointers generates signed overflow
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 11 Aug 2017 08:03:16 +0000
- Subject: [Bug target/81801] [PATCH] Difference of two pointers generates signed overflow
- Auto-submitted: auto-generated
- References: <bug-81801-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81801
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |32bit target
Component|c |target
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually it is worse than you think. The problem is __PTRDIFF_TYPE__ is
defined incorrectly if pointers can span across the sign bit (32bit). There is
whole thread about this on gcc@. The C/C++ language defines ptrdiff_t as a
type which can be used two take a difference of any two valid pointers and get
a signed difference.
In the case here 0x8002000f-0x0001000f should actually return a signed integer
that represents the space between those two pointers.