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

2018-08-26 Thread jvg1981 at aim dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #20 from Joshua Green --- > "But if we don't know which pointer is greater, it gets more complicated: > ..." > > I'm not sure that this is true. For types that are larger than 1 byte, it > seems that one can do the subtraction

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

2018-08-21 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #19 from Marc Glisse --- This seems fixed in gcc-8, no?

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

2018-08-21 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #18 from joseph at codesourcery dot com --- On Tue, 21 Aug 2018, jvg1981 at aim dot com wrote: > intptr_t pVal = ((uintptr_t) p)/(sizeof *p); > intptr_t qVal = ((uintptr_t) q)/(sizeof *q); Note that this can be expanded

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

2018-08-21 Thread jvg1981 at aim dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 Joshua Green changed: What|Removed |Added CC||jvg1981 at aim dot com --- Comment #17

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

2015-11-23 Thread fw at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #14 from Florian Weimer --- (In reply to Szabolcs Nagy from comment #13) > if gcc treats p-q as (ssize_t)p-(ssize_t)q and makes > optimization decisions based on signed int range then > that's broken and leads to wrong code gen.

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

2015-11-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 Richard Biener changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed|

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

2015-11-23 Thread ch3root at openwall dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #16 from Alexander Cherepanov --- On 2015-11-23 14:58, rguenth at gcc dot gnu.org wrote: > Note that in practice it needs exposal of the address constant to trigger the > bogus optimization. No. The program: #include #include

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

2015-11-22 Thread nszabolcs at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 Szabolcs Nagy changed: What|Removed |Added CC||nszabolcs at gmail dot com --- Comment

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

2015-10-19 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #12 from Richard Biener --- (In reply to Jakub Jelinek from comment #3) > The problem is that we don't have a POINTER_DIFF_EXPR similar to > POINTER_PLUS_EXPR, which would take two pointers and return an integer, and > the FEs emit

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

2014-09-22 Thread rguenth at gcc dot gnu.org
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

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

2014-09-22 Thread mikulas at artax dot karlin.mff.cuni.cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #11 from mikulas at artax dot karlin.mff.cuni.cz --- Richard Biener: if the middle end tells us that one pointer is greater or equal than the other pointer, we could do unsigned subtraction and shift. But if we don't know which

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

2014-09-19 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added CC||jakub at gcc dot

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

2014-09-19 Thread mikulas at artax dot karlin.mff.cuni.cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #2 from mikulas at artax dot karlin.mff.cuni.cz --- Jakub Jelinek: I know, but the problem happened in perfectly valid program. Suppose that you do: char *p = malloc(0x2000); - the allocator allocates the array at 0x7000.

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

2014-09-19 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added CC||jason at gcc dot

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

2014-09-19 Thread mikulas at artax dot karlin.mff.cuni.cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #4 from mikulas at artax dot karlin.mff.cuni.cz --- ... and another related problem (try this on 32-bit system): #include stdio.h #include stdlib.h int main(void) { short *a = malloc(0x5000 * sizeof(short));

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

2014-09-19 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #5 from Jakub Jelinek jakub at gcc dot gnu.org --- (In reply to mikulas from comment #4) ... and another related problem (try this on 32-bit system): #include stdio.h #include stdlib.h int main(void) { short *a =

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

2014-09-19 Thread mikulas at artax dot karlin.mff.cuni.cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #6 from mikulas at artax dot karlin.mff.cuni.cz --- you really can't have an object bigger than half of the address space in C/C++ - where does the standard claim this? If this is true, we should change malloc so that it doesn't

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

2014-09-19 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #7 from joseph at codesourcery dot com joseph at codesourcery dot com --- Yes, I consider it a bug in malloc that it produces objects 2GB or more in size on 32-bit systems (because of the one-past-end address, the largest size that

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

2014-09-19 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303 --- Comment #8 from Jakub Jelinek jakub at gcc dot gnu.org --- (In reply to mikulas from comment #6) Regarding pointer difference, the C standard says this: When two pointers are subtracted, both shall point to elements of the same array

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

2014-09-19 Thread mikulas at artax dot karlin.mff.cuni.cz
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