Path: utzoo!telly!philmtl!uunet!shelby!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!EDDIE.MIT.EDU!mcgill-vision!hcr!david From: mcgill-vision!hcr!david@EDDIE.MIT.EDU Newsgroups: gnu.gcc.bug Subject: Bug in handling of conversion from float to double (on stack) Message-ID: <8912141938.AA08227@zeus.UUCP> Date: 14 Dec 89 19:38:16 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: HCR Corporation, 130 Bloor St. W., Toronto, Ontario Lines: 64 gcc version: 1.36 os version: Interactive 386/ix 1.0.6 (System V Rel 3.1) the following code cause a core dump when compiled with "gcc -O" main() { float f; f = 0; printf("%g, %g\n", f, f); } This is because the un-named instruction describing how to move a double from a float register to the top of the stack does not take into account the fact that popping from the 387 register stack invalidates the contents of the register. I would guess that the same thing would happen on a Sun 386 system. Here is a patch to fix the problem. It is similar to the code in the other (named) insn's to check if the register is still needed. *** md Mon Dec 11 09:26:24 1989 --- config/i386.md Thu Dec 14 14:29:32 1989 *************** *** 390,396 **** xops[2] = stack_pointer_rtx; /* fp_pop_level--; */ output_asm_insn (AS2 (sub%L0,%1,%2), xops); ! output_asm_insn (\"fstp%S0 %0\", xops); RET; } return \"push%L0 %1\"; --- 390,399 ---- xops[2] = stack_pointer_rtx; /* fp_pop_level--; */ output_asm_insn (AS2 (sub%L0,%1,%2), xops); ! if (top_dead_p(insn)) ! output_asm_insn (\"fstp%S0 %0\", xops); ! else ! output_asm_insn (\"fst%S0\", xops); RET; } return \"push%L0 %1\"; *************** *** 426,432 **** xops[2] = stack_pointer_rtx; /* fp_pop_level--; */ output_asm_insn (AS2 (sub%L0,%1,%2), xops); ! output_asm_insn (\"fstp%Q0 %0\", xops); RETCOM (pushdf); } else --- 429,438 ---- xops[2] = stack_pointer_rtx; /* fp_pop_level--; */ output_asm_insn (AS2 (sub%L0,%1,%2), xops); ! if (top_dead_p(insn)) ! output_asm_insn (\"fstp%Q0 %0\", xops); ! else ! output_asm_insn (\"fst%Q0 %0\", xops); RETCOM (pushdf); } else