From 291da8a0624d3844d30931d0e89f51e3daf03a61 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Fri, 14 Sep 2012 12:53:13 +0100 Subject: Check for Int constants that are too large in mkDerivedConstants --- includes/mkDerivedConstants.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'includes') diff --git a/includes/mkDerivedConstants.c b/includes/mkDerivedConstants.c index 92024d3833..28377efa90 100644 --- a/includes/mkDerivedConstants.c +++ b/includes/mkDerivedConstants.c @@ -294,6 +294,20 @@ enum Mode { Gen_Haskell_Type, Gen_Haskell_Value, Gen_Haskell_Wrappers, Gen_Haske #define FUN_OFFSET(sym) (OFFSET(Capability,f.sym) - OFFSET(Capability,r)) void constantInt(char *name, intptr_t val) { + /* If the value is larger than 2^28 or smaller than -2^28, then fail. + This test is a bit conservative, but if any constants are roughly + maxBoun or minBound then we probably need them to be Integer + rather than Int so that cross-compiling between 32bit and 64bit + platforms works. */ + if (val > 268435456) { + printf("Value too large for constantInt: %" PRIdPTR "\n", val); + exit(1); + } + if (val < -268435456) { + printf("Value too small for constantInt: %" PRIdPTR "\n", val); + exit(1); + } + switch (mode) { case Gen_Haskell_Type: printf(" , pc_%s :: Int\n", name); -- cgit v1.2.1