[MLton-commit] r7464
Matthew Fluet
fluet at mlton.org
Tue May 18 19:33:36 PDT 2010
Cast offsetof and sizeof GC constants to Word32.
The various GC constants are emitted by code like:
fprintf (stdout, "stackTop_Offset = %"PRIu32"\n", offsetof (struct GC_state, stackTop));
The constants are known to be small, so Word32 suffices to represent
the offsets and sizes. However, on a 64-bit platform, offsetof and
sizeof return a 64-bit unsigned integer. Although not observed in
practice, an ABI might have sufficiently different calling conventions
for 32-bit and 64-bit values that passing a 64-bit value where a
varargs function expects a 32-bit value would not simply see the low
32-bits of the 64-bit value.
The simple solution is to cast the offsetof and sizeof expressions to
Word32 before passing them to fprintf.
----------------------------------------------------------------------
U mlton/trunk/mlton/main/lookup-constant.fun
----------------------------------------------------------------------
Modified: mlton/trunk/mlton/main/lookup-constant.fun
===================================================================
--- mlton/trunk/mlton/main/lookup-constant.fun 2010-05-18 10:57:46 UTC (rev 7463)
+++ mlton/trunk/mlton/main/lookup-constant.fun 2010-05-19 02:33:35 UTC (rev 7464)
@@ -1,4 +1,5 @@
-(* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 2010 Matthew Fluet.
+ * Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
*
@@ -68,12 +69,14 @@
val gcFieldsOffsets =
List.map (gcFields, fn s =>
{name = s ^ "_Offset",
- value = concat ["offsetof (struct GC_state, ", s, ")"],
+ value = concat ["(", Ffi.CType.toString Ffi.CType.Word32 ,")",
+ "(offsetof (struct GC_state, ", s, "))"],
ty = ConstType.Word WordSize.word32})
val gcFieldsSizes =
List.map (gcFields, fn s =>
{name = s ^ "_Size",
- value = concat ["sizeof (gcState.", s, ")"],
+ value = concat ["(", Ffi.CType.toString Ffi.CType.Word32 ,")",
+ "(sizeof (gcState.", s, "))"],
ty = ConstType.Word WordSize.word32})
fun build (constants, out) =
More information about the MLton-commit
mailing list