🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Bruce_Martin Wed, 15 Apr 1992 01:01
GCC 2.1 codegen bug when function is declared volatile
#405
Author: Bruce_Martin
Date: Wed, 15 Apr 1992 01:01
71 lines
1952 bytes
Gcc Version: 2.1
Configuration: i386-mach
Reported by: Bruce Martin (Bruce_Martin@NeXT.COM)

Description: if a function is declared volatile, gcc 2.1 produces
completely bogus code when the optimizer is used.  I'm not at all
sure what the correct response to the following C code should be,
but the current behavior is definitely wrong (I'm assuming that
the lack of any error messages means that the compiler should
succeed in the compilation).

Things work correctly when the optimizer is not used.

Test case:

	compiled with: cc1 -O -o foo.s foo.c

foo.c:

main()
{
    volatile double     result1, result2;
    volatile double     one_over(double);

    do {
        result1 = one_over(12);
        result2 = one_over(12);
    } while (result1 == result2);
    exit(0);
}

double
one_over(       double  x)
{
    return (double)( 1.0 / x );
}




Result of the compilation (note the lack of any code in main to
test the return value of one_over, or a call to exit()):

        .file   "foo.c"
gcc2_compiled.:
.text
        .align 2
.globl _main
_main:
        pushl %ebp
        movl %esp,%ebp
        subl $16,%esp
        call ___main
        pushl $1076363264
        pushl $0
        call _one_over
        fstp %st(0)
        .align 2,0x90
        .align 2
LC0:
        .double 0d1.00000000000000000000e+00
        .align 2
.globl _one_over
_one_over:
        pushl %ebp
        movl %esp,%ebp
        fldl LC0
        fdivl 8(%ebp)
        leave
        ret
        .align 2,0x90
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads