This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]