Give -fwrapv to gcc when it supports it
authorIan Lynagh <igloo@earth.li>
Mon, 15 Jan 2007 19:42:50 +0000 (19:42 +0000)
committerIan Lynagh <igloo@earth.li>
Mon, 15 Jan 2007 19:42:50 +0000 (19:42 +0000)
Fixes trac #952: Haskell requires consistent overflow behaviour, which
gcc doesn't give without this flag.

aclocal.m4
compiler/main/DriverPipeline.hs
configure.ac

index 86fdeaf..36c0128 100644 (file)
@@ -954,6 +954,18 @@ if test "$fp_cv_gcc_has_no_unit_at_a_time" = "yes"; then
    AC_DEFINE([HAVE_GCC_HAS_NO_UNIT_AT_A_TIME], [1], [Define to 1 if gcc supports -fno-unit-at-a-time.])
 fi])
 
+# FP_GCC_HAS_WRAPV
+# --------------------------
+AC_DEFUN([FP_GCC_HAS_WRAPV],
+[AC_REQUIRE([FP_HAVE_GCC])
+AC_CACHE_CHECK([whether gcc has -fwrapv], [fp_cv_gcc_has_wrapv],
+[FP_COMPARE_VERSIONS([$fp_gcc_version], [-ge], [3.4],
+  [fp_cv_gcc_has_wrapv=yes],
+  [fp_cv_gcc_has_wrapv=no])])
+if test "$fp_cv_gcc_has_wrapv" = "yes"; then
+   AC_DEFINE([HAVE_GCC_HAS_WRAPV], [1], [Define to 1 if gcc supports -fwrapv.])
+fi])
+
 # FP_SETUP_PROJECT_VERSION
 # ---------------------
 AC_DEFUN([FP_SETUP_PROJECT_VERSION],
index fddeb6d..59f0721 100644 (file)
@@ -880,6 +880,10 @@ runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc
                       ++ split_opt
                       ++ include_paths
                       ++ pkg_extra_cc_opts
+#ifdef HAVE_GCC_HAS_WRAPV
+                  -- We need consistent integer overflow (trac #952)
+               ++ ["-fwrapv"]
+#endif
                       ))
 
        return (next_phase, dflags, maybe_loc, output_fn)
index 8b00e5a..85301aa 100644 (file)
@@ -878,6 +878,7 @@ FP_HAVE_GCC
 FP_MINGW_GCC
 FP_GCC_NEEDS_NO_OMIT_LFPTR
 FP_GCC_HAS_NO_UNIT_AT_A_TIME
+FP_GCC_HAS_WRAPV
 
 dnl ** figure out how to invoke cpp directly (gcc -E is no good)
 AC_PROG_CPP