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--).
| otherwise = As
output_fn <- get_output_fn next_phase 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.
SysTools.runCc dflags (
-- force the C compiler to interpret this file as C when
-- compiling .hc files, by adding the -x c option.
++ (if hcc && mangle
then md_regd_c_flags
else [])
++ (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
++ [ 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
))
++ include_paths
++ pkg_extra_cc_opts
))