This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Codegen bug in current CVS on x86
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: Re: Codegen bug in current CVS on x86
- From: Zack Weinberg <zack at rabi dot columbia dot edu>
- Date: Wed, 10 Feb 1999 11:06:32 -0500
On Wed, 10 Feb 1999 10:32:26 -0500, Zack Weinberg wrote:
>
>The present CVS tree miscompiles glibc's strncpy.c, such that under
>some conditions it will segfault when handed perfectly well-formed
>arguments. I've been unable to come up with a self-contained
>testcase, but this reliably happens when strncpy is used by the
>`rpcgen' program as part of the libc build.
>
>I've attached the C source for strncpy.c and the assembly output for
>egcs 1.1.1 and the current snapshot (-O2 -mpentium). I think the
>problem is that the source pointer sometimes gets initialized to
>garbage, but I get lost in all those pointless flushes to memory...
Replying to myself...
The bug is here:
...
jmp .L4
.p2align 4,,7
.L10:
movl %edi,-28(%ebp)
leal 1(%ecx),%eax
movl %eax,-24(%ebp)
leal 3(%ecx),%esi
movl %esi,-16(%ebp)
decl -8(%ebp)
jz .L12
.L4:
movl -16(%ebp),%esi
movb -3(%esi),%al
movl -28(%ebp),%esi
...
The jump to .L4 skips initialization of the stack slots that are used
in the inner loop. This only happens the first time through the loop,
but that's enough to be lethal.
Probably the bug is in loop or jump - the code to duplicate/merge loop
prologues?
Another question is why we get such atrocious register usage, but
first let's make it correct...
zw