diff options
author | Ian Lynagh <ian@well-typed.com> | 2012-09-14 12:53:13 +0100 |
---|---|---|
committer | Ian Lynagh <ian@well-typed.com> | 2012-09-14 12:53:13 +0100 |
commit | 291da8a0624d3844d30931d0e89f51e3daf03a61 (patch) | |
tree | 1e243803596b41976fef9841a8cee4eeb086029b /includes | |
parent | 9b0c4ed70cb4394bb293e4e6f863f877debcd655 (diff) | |
download | haskell-291da8a0624d3844d30931d0e89f51e3daf03a61.tar.gz |
Check for Int constants that are too large in mkDerivedConstants
Diffstat (limited to 'includes')
-rw-r--r-- | includes/mkDerivedConstants.c | 14 |
1 files changed, 14 insertions, 0 deletions
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); |