This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
gcc-2.95 19990629 miscompiles makeinfo.c
- To: egcs at egcs dot cygnus dot com
- Subject: gcc-2.95 19990629 miscompiles makeinfo.c
- From: Alexander Sokolov <robocop at amur dot rosnet dot ru>
- Date: Fri, 2 Jul 1999 20:38:14 +1100 (VLAST)
Building the latest gcc-2.95 snapshot I encountered with miscompilation
of makeinfo which segfaulted in get_until() when attempting to make
cpp.info. Take a look at the part of C source from makeinfo.c
get_until (match, string)
char *match, **string;
{
int len, current_point, x, new_point, tem;
current_point = x = input_text_offset;
new_point = search_forward (match, input_text_offset);
if (new_point < 0)
new_point = size_of_input_text;
...
and the assembler code generated by gcc-2.95 19990629 with -O2
-fomit-frame-pointer -march=pentiumpro options:
get_until:
subl $28,%esp
pushl %ebp
pushl %edi
pushl %esi
pushl %ebx
movl 48(%esp),%ebx
movl input_text_offset,%edi
addl $-8,%esp
pushl %edi
pushl %ebx
call search_forward
addl $16,%esp
%eax now contains new_point returned by search_forward() which should be
compared to 0. The obvious way is cmpl $0,%eax or even testl %eax,%eax but
look what gcc generates instead:
cmpl $0,28(%esp)
cmovl size_of_input_text,%eax
movl %eax,28(%esp)
This code is incorrect because 28(%esp) contains garbage but not
new_point. Note that both -O1 and -O3 generate the correct code.
--
Alexander Sokolov
System Administrator
ROSNET Komsomolsk-na-Amure
Tel./Fax: +7-095-737-6260