🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #405

GCC 2.1 codegen bug when function is declared volatile

#405
From: 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
Technical Details
Message-ID: <9204150101.AA19311@oz.NeXT.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!next.com!Bruce_Martin

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!next.com!Bruce_Martin
From: Bruce_Martin@next.com
Subject: GCC 2.1 codegen bug when function is declared volatile
Message-ID: <9204150101.AA19311@oz.NeXT.COM>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 15 Apr 1992 01:01:38 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 72