From 033418425ff8b4591580bf2bc4476b7ecc203ba6 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 8 Nov 2005 12:56:04 +0000 Subject: [PATCH] [project @ 2005-11-08 12:56:04 by simonmar] gcc's -fstrict-aliasing is biting us when we use the stack to store different types of objects. For example: *((StgDouble*)((W_)Sp-8)) = *((StgDouble*)((W_)Sp+8)); Sp[1] = (W_)&s1Cx_info; gcc feels free to reorder these two lines, because they refer to differently typed objects, even though the assignment to Sp[1] clearly aliases the read from the same location. Trying to fix this by accessing locations using union types might be possible, but I took the sledgehammer approach of -fno-strict-aliasing. This is justified to a certain extent because our generated C code is derived from a very weakly-typed internal language (C--). --- ghc/compiler/main/DriverPipeline.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ghc/compiler/main/DriverPipeline.hs b/ghc/compiler/main/DriverPipeline.hs index 07fe113..d1fa5ba 100644 --- a/ghc/compiler/main/DriverPipeline.hs +++ b/ghc/compiler/main/DriverPipeline.hs @@ -852,6 +852,23 @@ runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc | otherwise = As output_fn <- get_output_fn next_phase maybe_loc + let + more_hcc_opts = +#if x86_TARGET_ARCH + -- on x86 the floating point regs have greater precision + -- than a double, which leads to unpredictable results. + -- By default, we turn this off with -ffloat-store unless + -- the user specified -fexcess-precision. + (if excessPrecision then [] else [ "-ffloat-store" ]) ++ +#endif + -- gcc's -fstrict-aliasing allows two accesses to memory + -- to be considered non-aliasing if they have different types. + -- This interacts badly with the C code we generate, which is + -- very weakly typed, being derived from C--. + ["-fno-strict-aliasing"] + + + SysTools.runCc dflags ( -- force the C compiler to interpret this file as C when -- compiling .hc files, by adding the -x c option. @@ -868,13 +885,13 @@ runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc ++ (if hcc && mangle then md_regd_c_flags else []) + ++ (if hcc + then more_hcc_opts + else []) ++ [ verb, "-S", "-Wimplicit", "-O" ] ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ] ++ cc_opts ++ split_opt -#if x86_TARGET_ARCH - ++ (if excessPrecision then [] else [ "-ffloat-store" ]) -#endif ++ include_paths ++ pkg_extra_cc_opts )) -- 1.7.10.4