[Bug sanitizer/82802] Potential UBSAN error with pointer difference (32-bits mode)

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 2 10:34:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82802

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |glisse at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
   Target Milestone|6.5                         |---
      Known to fail|                            |5.4.0, 7.2.0

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think this was noted by Jakub somewhere - the FE converts the pointers to
signed integer for the subtraction which causes the issue for pointers into
objects that "wrap" around the "half" address-space.

POINTER_DIFF_EXPR is supposed to allow fixing this.

A band-aid would be to perform the subtraction in an unsigned type, then
casting the result to a signed type to do the division by the element size.
I think Jakub did this and there was some fallout.


More information about the Gcc-bugs mailing list