GCC-4 compiler bug

Matthew Dillon dillon at apollo.backplane.com
Tue Nov 27 13:30:15 PST 2007


    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 at backplane.com>






More information about the Kernel mailing list