This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[BUG] of optimizer


D:\usr\src\tests>gcc -v
Reading specs from \usr\H-i386-cygwin32\lib\gcc-lib\i386-cygwin32\egcs-2.91.34\s
pecs
gcc version egcs-2.91.34 19980531 (gcc2 ss-980502 experimental)

When optimization is enabled, the compiler emits a wrong code for the following C sample:

D:\usr\src\tests>cat bug.c
int f(unsigned char *p, unsigned char *e)
{
        unsigned char *savep;
        savep=p;
        if(f1(&p, e) < 0)
                return -1;
        return p-savep;
}

D:\usr\src\tests>gcc -S bug.c -O1


D:\usr\src\tests>cat bug.s
        .file   "bug.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
        .align 4
.globl _f
_f:
        pushl %ebp
        movl %esp,%ebp
        pushl 12(%ebp)
        leal 8(%ebp),%edx
        pushl %edx
        call _f1
        testl %eax,%eax
        jl L2
>        movl 8(%ebp),%eax
>        movl %eax,%edx
>        subl %eax,%edx
>        movl %edx,%eax
        jmp L3
        .p2align 4,,7
L2:
        movl $-1,%eax
L3:
        leave
        ret

The storage for savep is not allocated, marked instructions always return 0.

-- 
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]