[MLton] Real.fromLargeInt buggy (64 bit)

Wesley W. Terpstra terpstra at dvs1.informatik.tu-darmstadt.de
Wed Nov 28 07:37:30 PST 2007


On Nov 28, 2007, at 4:01 PM, Matthew Fluet wrote:
> On Wed, 28 Nov 2007, Wesley W. Terpstra wrote:
>>> terpstra at tokyo:~$ ./bug
>>> 3 6
>>> terpstra at tokyo:~$ cat bug.sml
>>> val x = Real.fromLargeInt 3
>>> val y = Real.toInt IEEEReal.TO_ZERO x
>>> val () = print (Int.toString 3 ^ " " ^ Int.toString y ^ "\n")
> I suspect that something is amiss in your cross-compiler.

Indeed. It seems that libgdtoa.a was miscompiled.
Searching further, I found the problem:

> cd gdtoa && gcc -std=gnu99 -o arithchk.out arithchk.c
> cd gdtoa && ./arithchk.out >arith.h
> cd gdtoa && 						\
> 		gcc -std=gnu99 -I. -Iplatform  -m64  -O2 -fomit-frame-pointer  - 
> pedantic -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -Wswitch- 
> default -Wswitch-enum -Wuninitialized -Winit-self -Wstrict- 
> aliasing=2 -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad- 
> function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate- 
> return -Wstrict-prototypes -Wold-style-definition -Wmissing- 
> prototypes -Wmissing-declarations -Wmissing-field-initializers - 
> Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls - 
> Wnested-externs -Wlong-long  -Wdisabled-optimization  -Winline		\
> 			-w -O1 -c -DINFNAN_CHECK 		\
> 			*.c

The first compile of arithchk.c is done 32 bit.
The second compile of libgdtoa is done 64 bit (-m64).

Only with -m64 do you get
> #define IEEE_8087
> #define Arith_Kind_ASL 1
> #define Long int
> #define Intcast (int)(long)
> #define Double_Align
> #define X64_bit_pointers
Otherwise you get
> #define IEEE_8087
> #define Arith_Kind_ASL 1

Fix:
Index: runtime/Makefile
===================================================================
--- runtime/Makefile	(revision 6219)
+++ runtime/Makefile	(working copy)
@@ -244,7 +244,7 @@
  	patch -s -p0 <gdtoa-patch

  gdtoa/arithchk.out: gdtoa/arithchk.c
-	cd gdtoa && $(CC) -o arithchk.out arithchk.c
+	cd gdtoa && $(CC) $(OPTCFLAGS) -o arithchk.out arithchk.c

  gdtoa/arith.h: gdtoa/arithchk.out
  	cd gdtoa && ./arithchk.out >arith.h




More information about the MLton mailing list