🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Mike Stump Wed, 15 Apr 1992 22:47
Re: GCC 2.1 codegen bug when function is declared volatile
#430
Author: Mike Stump
Date: Wed, 15 Apr 1992 22:47
93 lines
2823 bytes
Please cite ANSI or any standard or any non-standard or any compiler
that accepts that code without complaints.

You probably cannot.  If you can, it is probably a broken compiler.

If you even tried gcc with -pedantic -ansi you would get errors:

t10.c: In function `main':
t10.c:4: warning: ANSI C forbids const or volatile functions

If you remove the volatile keyword, the code works.

Please see the documentation of volatile function in the gcc
distribution for exact semantics.

> Message-Id: <9204150101.AA19311@oz.NeXT.COM>
> Date: Tue, 14 Apr 92 18:01:38 PDT
> From: Bruce_Martin@next.com
> Received: by NeXT Mailer (1.63)
> To: bug-gcc@prep.ai.mit.edu
> Subject: GCC 2.1 codegen bug when function is declared volatile

> 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