This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/63303] Pointer subtraction is broken when using -fsanitize=undefined
- From: "mikulas at artax dot karlin.mff.cuni.cz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Sep 2014 15:50:19 +0000
- Subject: [Bug c/63303] Pointer subtraction is broken when using -fsanitize=undefined
- Auto-submitted: auto-generated
- References: <bug-63303-4 at http dot gcc dot gnu dot org/bugzilla/>
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(0x50000000 * sizeof(short));
short *b = a + 0x50000000;
printf("%ld\n", (long)(b - a));
return 0;
}
Here, the return value should be positive (0x50000000), but it is negative.
IMHO, according to the C standard, this is program correct and positive result
should be returned.
The problem is that it is not easy to fix it without performance penalty and
all compilers that I tried (gcc, clang, icc, suncc, opencc, nwcc) print
negative result.