This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Results with glibc-2.2.91
- From: Roland McGrath <roland at redhat dot com>
- To: Art Haas <ahaas at neosoft dot com>
- Cc: libc-alpha at sources dot redhat dot com, jakub at redhat dot com
- Date: Thu, 29 Aug 2002 13:27:30 -0700
- Subject: Re: Results with glibc-2.2.91
- References: <20020829134649.GC11683@debian>
This appears to be a GCC bug. stpcpy is defined by a macro so the
beginning of test_stpcpy looks like this:
it = "stpcpy";
check (((__extension__ (__builtin_constant_p ("a") ? (((size_t)(const void *)(("a") + 1) - (size_t)(const void *)("a") == 1) && strlen ("a") + 1 <= 8 ? __builtin_strcpy (one, "a") + strlen ("a") : ((char *) (__mempcpy) (one, "a", strlen ("a") + 1) - 1)) : __stpcpy (one, "a"))) - one) == 1, 1);
The code generated by gcc is this highly suspicious nonsense (-march=i586 -O2):
test_stpcpy:
pushl %ebp
movl %esp, %ebp
pushl %edi
pushl %esi
movl $1, %esi
pushl %ebx
movl $one, %ebx
subl %ebx, %esi
subl $20, %esp
movl $.LC14, it
leal (%ebx,%esi), %edi
pushl $1
cmpl $1, %edi
addl $one+2, %esi BAD, clobbers cc
sete %al
andl $255, %eax
pushl %eax
movw $97, one
call check
addl $12, %esp
I don't know why it is doing all that silly arithmetic and comparison.
In a simple case (the expanded C above in a function alone) it justs
folds it all down to a constant 1. But what makes it incorrect is
scheduling the add between the cmpl and the sete. The add insn
clobbers the condition codes.