Bad C code generation, egcs-980914, short example
Paul Henning
phenning@cs.uiowa.edu
Wed Sep 30 23:48:00 GMT 1998
Reading specs from
/usr/local/app/egcs-19980914/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.92.07/specs
gcc version egcs-2.92.07 19980914 (gcc2 ss-980609 experimental)
egcs-980914 is miscompiling teTeX-0.9 (a really nice TeX/LaTeX/etc
distribution), and I isolated the problem to the following bit of
preprocessed C code:
# 1 "ha.c"
extern long curcs;
extern long curtok;
void gettoken(void);
void getrtoken (void)
{
lab20:
do { gettoken(); } while(curtok == 2592);
if (curcs == 0) goto lab20 ;
}
when this is compiled with: gcc -v -O2 -S ha.i
I get the following code:
gcc2_compiled.:
.text
.align 4
.globl getrtoken
.type getrtoken,@function
getrtoken:
pushl %ebp
movl %esp,%ebp
pushl %ebx
.L2:
movl curtok,%ebx
.p2align 4,,7
.L3:
call gettoken
cmpl $2592,%ebx
je .L3
(plus some more stuff)
The problem is that %ebx is getting loaded with the value of curtok
before the call to gettoken. Of course, gettoken is changing curtok
as a side-effect, and the whole comparison is get hosed. Adding
--no-force-mem makes the problem go away by not doing the compare in
the register.
Thanks,
Paul Henning
paul-henning@uiowa.edu http://www.cs.uiowa.edu/~phenning
More information about the Gcc-bugs
mailing list