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

mikulas at artax dot karlin.mff.cuni.cz gcc-bugzilla@gcc.gnu.org
Fri Sep 19 16:29:00 GMT 2014


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

--- Comment #9 from mikulas at artax dot karlin.mff.cuni.cz ---
> See what I wrote, any object size bigger than half of address space really
> isn't supportable, because then (char *) (P) - (char *) (Q) might not fit into
> ptrdiff_t.  There is no point slowing down all pointer subtractions (other than
> char/signed char/unsigned char pointers) for something that really wouldn't
> work reliably anyway.

But the code in comment 4 doesn't perform (char *)P - (char *)Q. It performs
(short *)P - (short *)Q. And that result clearly fits into the signed ptrdiff_t
type.

If the code in comment 4 performed (char *)b - (char *)a, that operation would
be invalid because of overflow. But it doesn't.



More information about the Gcc-bugs mailing list