From 9145c993eab0a511169bf1dd2f6bfbbaff79ba64 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 23 Jan 2009 15:50:06 +0000 Subject: [PATCH] Fixed the constant folding to use a type for Int based on the compilation target rather than just assuming Int32 However, it is possible that there will still be a problem if the C and C++ compiler have different int sizes, because the constant folding has to know the type at compile time, and thus we have to arbitrarily choose to use the C version. In future, we could perhaps swap all Ints for the appropriate substiution (e.g. Int64) at run-time, based on the flags and prior knowledge about C/C++ int sizes --- common/EvalLiterals.hs | 3 ++- config/TypeSizes.hs.in | 9 +++++++++ configure.ac | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/common/EvalLiterals.hs b/common/EvalLiterals.hs index c047bf3..c645eef 100644 --- a/common/EvalLiterals.hs +++ b/common/EvalLiterals.hs @@ -33,6 +33,7 @@ import qualified AST as A import CompState hiding (CSM) -- everything here is read-only import Errors import Metadata +import TypeSizes type EvalM = ErrorT ErrorReport (StateT CompState Identity) @@ -48,7 +49,7 @@ data OccValue = | OccUInt64 Word64 | OccInt8 Int8 | OccInt16 Int16 - | OccInt Int32 + | OccInt CIntReplacement | OccInt32 Int32 | OccInt64 Int64 | OccArray [OccValue] diff --git a/config/TypeSizes.hs.in b/config/TypeSizes.hs.in index 419a5f9..b77b2df 100644 --- a/config/TypeSizes.hs.in +++ b/config/TypeSizes.hs.in @@ -1,8 +1,17 @@ -- | This module is auto-generated by autoconf from TypeSizes.hs.in module TypeSizes where +import Data.Int +import qualified AST as A + cBoolSize, cxxBoolSize, cIntSize, cxxIntSize :: Int cBoolSize = @C_BOOL_SIZE@ cxxBoolSize = @CXX_BOOL_SIZE@ cIntSize = @C_INT_SIZE@ cxxIntSize = @CXX_INT_SIZE@ +type CIntReplacement = @C_INT_EQUIV@ +type CXXIntReplacement = @CXX_INT_EQUIV@ +cIntReplacement, cXXIntReplacement :: A.Type +cIntReplacement = A.@C_INT_EQUIV@ +cXXIntReplacement = A.@CXX_INT_EQUIV@ + diff --git a/configure.ac b/configure.ac index 0e152d6..8e8dca4 100644 --- a/configure.ac +++ b/configure.ac @@ -193,6 +193,27 @@ AC_CHECK_SIZEOF(int) AC_COMPUTE_INT(C_INT_SIZE,SIZEOF_INT) AC_SUBST(C_INT_SIZE) +if test "x$C_INT_SIZE" = "x2"; then +C_INT_EQUIV=Int16 +fi +if test "x$C_INT_SIZE" = "x4"; then +C_INT_EQUIV=Int32 +fi +if test "x$C_INT_SIZE" = "x8"; then +C_INT_EQUIV=Int64 +fi +if test "x$CXX_INT_SIZE" = "x2"; then +CXX_INT_EQUIV=Int16 +fi +if test "x$CXX_INT_SIZE" = "x4"; then +CXX_INT_EQUIV=Int32 +fi +if test "x$CXX_INT_SIZE" = "x8"; then +CXX_INT_EQUIV=Int64 +fi +AC_SUBST(C_INT_EQUIV) +AC_SUBST(CXX_INT_EQUIV) + CFLAGS="$CFLAGS $no_strict_overflow $no_tree_vrp" # The reason for -fno-strict-overflow and -fno-tree-vrp above is that with the way I have implemented # range checking, on GCC 4.3.2 (and probably other versions), GCC has