Bug in egcs

Lars Heete hel@admin.de
Tue Sep 8 01:05:00 GMT 1998


Hello,

egcs-1.1, at least on i386, seems to have bad problems with assignments to
typecasted pointers to variables, when optimization is enabled.
It  enerates wrong code for the following small function.

Lars Heete <hel@admin.de>
--------------------------------------------------

int test(char *s)
{
  int v = 0;
  *(char *)(&v) = *s ;
  return v;
} 

With optimization "-O" the code generated is:
-----------------------------------------------------------
         .file   "t.c"
        .version        "01.01"
gcc2_compiled.:
..text
        .align 4
..globl test
        .type    test,@function
test:
        pushl %ebp
        movl %esp,%ebp
        movl 8(%ebp),%eax
        movb (%eax),%al       <-- bad, %eax is not cleared (v = 0 ignored)
        movl %ebp,%esp
        popl %ebp
        ret
..Lfe1:
        .size    test,.Lfe1-test
        .ident  "GCC: (GNU) egcs-2.91.57 19980901 (egcs-1.1 release)"



More information about the Gcc-bugs mailing list