Rework previous: not a gcc bug after all
authorSimon Marlow <simonmar@microsoft.com>
Thu, 23 Mar 2006 16:12:29 +0000 (16:12 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Thu, 23 Mar 2006 16:12:29 +0000 (16:12 +0000)
It turns out that we were relying on behaviour that is undefined in C,
and undefined behaviour in C means "the compiler can do whatever the
hell it likes with your entire program".  So avoid that.

GHC/Show.lhs
Makefile

index 8673357..15e5913 100644 (file)
@@ -397,12 +397,13 @@ showSignedInt (I# p) (I# n) r
 
 itos :: Int# -> String -> String
 itos n# cs
-    | n# <# 0# = let
-        n'# = negateInt# n#
-        in if n'# <# 0# -- minInt?
-            then '-' : itos' (negateInt# (n'# `quotInt#` 10#))
-                             (itos' (negateInt# (n'# `remInt#` 10#)) cs)
-            else '-' : itos' n'# cs
+    | n# <# 0# =
+       let I# minInt# = minInt in
+       if n# ==# minInt#
+               -- negateInt# minInt overflows, so we can't do that:
+          then '-' : itos' (negateInt# (n# `quotInt#` 10#))
+                             (itos' (negateInt# (n# `remInt#` 10#)) cs)
+          else '-' : itos' (negateInt# n#) cs
     | otherwise = itos' n# cs
     where
     itos' :: Int# -> String -> String
index 6078fba..cf5917c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -48,10 +48,6 @@ SRC_HSC2HS_OPTS += -Iinclude -I$(FPTOOLS_TOP)/ghc/includes
 # ESSENTIAL, for getting reasonable performance from the I/O library:
 SRC_HC_OPTS += -funbox-strict-fields
 
-# Grrr, gcc-4.1.0 has a bug in -O2 and higher that causes miscompilation of
-# GHC.Show.itos.  See gcc bug #26824.  We must drop back to -O1.
-GHC/Show_HC_OPTS += -optc-O1
-
 # -----------------------------------------------------------------------------
 # PrimOpWrappers