[gnu.gcc.bug] GCC bug concerning volatile

mike@APOLLO.COM (09/21/89)

The following simple C program shows a bug in gcc version 1.35 code generation :

        volatile
        struct foo {
                char    a, b, c;
        };
        
        tst()
        {
        struct  foo     *foo;
        
                foo = (struct foo *) 1234;
        
                foo->a = foo->c;
                foo->a = foo->c;
                foo->a = foo->c;
        }

The assembly output (68K) is :

        #NO_APP
        gcc_compiled.:
        .text
        	.even
        .globl tst
        tst:
        	link a6,#0
        	movew #1234,a0
        	moveb 1236:w,a0@
        	unlk a6
        	rts

Since the structure is marked as volatile the compiler should not be removing
redundant assignments.  A simple work around that I have been using is to mark
the pointer itself as volatile (eg. volatile struct foo *foo; ).

Mike Schloss
mike@apollo.hp.com
decvax!apollo!mike

rfg@ics.uci.edu (Ronald Guilmette) (09/22/89)

In article <8909201748.AA10157@xuucp.ch.apollo.com> mike@APOLLO.COM writes:
>The following simple C program shows a bug in gcc version 1.35 code generation :
>
>        volatile
>        struct foo {
>                char    a, b, c;
>        };

...
>Since the structure is marked as volatile...

I'm not 100% sure, but I believe that this is *not* a bug.  The way in
which volatile is used in the example above causes it to apply to nothing.
Specifically, it does *not* apply to the "struct type" itself.  If however
you had said something like:

	volatile struct foo { char a,b,c; } foo_var;

then I believe that the volatile would have applied to the variable called
foo_var (and nothing else).

// rfg