GCC-4 compiler bug

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Matthew Dillon
Date: Tuesday, November 27, 2007 - 2:23 pm

GCC-4.1.2 is not properly handling signed 64 bit rollovers.  It's
    not doing it properly for 32 bit rollovers either.

    This program should generate an "X" when run.  It doesn't.

int
main(int ac, char **av)
{
        int64_t n = 0x7FFFFFFFFFFFFFFFLL;

        if (n + (128 * 1024) + 1 < n)
                printf("X\n");
}

    If I replace the calculation with an assigned variable, it works:

int
main(int ac, char **av)
{
        int64_t n = 0x7FFFFFFFFFFFFFFFLL;
        int64_t o = n + (128 * 1024) + 1;

        if (o < n)
                printf("X\n");
}


test28# cc -v
Using built-in specs.
Target: 
Configured with: DragonFly/i386 system compiler
Thread model: posix
gcc version 4.1.2 (DragonFly)

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
GCC-4 compiler bug, Matthew Dillon, (Tue Nov 27, 2:23 pm)
Re: GCC-4 compiler bug, Simon 'corecode' Sch ..., (Tue Nov 27, 5:00 pm)
Re: GCC-4 compiler bug, Daniel Tralamazza, (Wed Nov 28, 6:45 pm)