[MLton] possible x86 codegen bug with 64-bit ints

Matthew Fluet fluet@cs.cornell.edu
Sat, 22 Jan 2005 08:39:47 -0500 (EST)


> This is a very weird bug, since, as you can see in the code, "pos"
> is an immutable value (a 64-bit integer).  The problem may be an x86
> codegen bug, since the program works fine when compiled -codegen c or
> -codegen bytecode.  Since the 64-bit stuff is pretty new, I suspect
> that is the problem area.

It is an x86 codegen bug.  The first call to Position.toString passes the 
pos argument as:

/* begin: SW64(60): Word64  = SW64(48): Word64 */
	movl (0+((48*1)+(0*1)))(%ebp),%esi
	movl %esi,(0+((60*1)+(0*1)))(%ebp)
	movl (0+((48*1)+(4*1)))(%ebp),%esi
	movl %esi,(0+((60*1)+(4*1)))(%ebp)
/* end: SW64(60): Word64  = SW64(48): Word64 */

while the second call to Position.toString passes the pos argument as:

/* begin: SW64(52): Word64  = SW64(48): Word64 */
	movl (0+((48*1)+(0*1)))(%ebp),%esi
	movl %esi,(0+((52*1)+(0*1)))(%ebp)
	movl (0+((48*1)+(4*1)))(%ebp),%esi
	movl %esi,(0+((52*1)+(4*1)))(%ebp)
/* end: SW64(52): Word64  = SW64(48): Word64 */

The x86 codegen wasn't taking into account the possibility that a 64-bit 
move could interfere with itself.  I should be able to check in a fix 
shortly.

> Incidentally, when I tried to compile this program with the CVS head
> MLton and -codegen bytecode, I got the following error:
> 
> missing opcode: Int32_storeStackOffset
> 
> I think this may have something to do with the recent changes (which I
> haven't yet had time to investigate) to type synonym replacement in
> the front end.

I believe that you can recover the old (buggy) behavior simply by 
changing  replaceSynonyms = false  to  replaceSynonyms = true
at line 2258 of elaborate-core.fun.