From 50ebea6a8607f4d83dd2d8d99acf9a55e4d39349 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 15 Jan 2007 19:42:50 +0000 Subject: [PATCH] Give -fwrapv to gcc when it supports it Fixes trac #952: Haskell requires consistent overflow behaviour, which gcc doesn't give without this flag. --- aclocal.m4 | 12 ++++++++++++ compiler/main/DriverPipeline.hs | 4 ++++ configure.ac | 1 + 3 files changed, 17 insertions(+) diff --git a/aclocal.m4 b/aclocal.m4 index 86fdeaf..36c0128 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -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], diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index fddeb6d..59f0721 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -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) diff --git a/configure.ac b/configure.ac index 8b00e5a..85301aa 100644 --- a/configure.ac +++ b/configure.ac @@ -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 -- 1.7.10.4