[Bug c/63303] Pointer subtraction is broken when using -fsanitize=undefined

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Sep 22 07:42:00 GMT 2014


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

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
To support the standards definition of p1 - p2 we'd need a POINTER_DIFF_EXPR
that also embeds the exact division by the array element size.

Btw, while C and C++ share pointer_int_sum they have differing implementations
for computing pointer differences.

The safe variant would be indeed to compute the pointer difference using an
unsigned type and I can't see what optimizations we lose when doing that.
Note that you'd still need to convert the result to a signed type before
doing the exact division by the element size.



More information about the Gcc-bugs mailing list