From f08c9e5b2196cd8374ef38b4358be4d3822c1465 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 23 Mar 2006 16:12:29 +0000 Subject: [PATCH] Rework previous: not a gcc bug after all 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 | 13 +++++++------ Makefile | 4 ---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/GHC/Show.lhs b/GHC/Show.lhs index 8673357..15e5913 100644 --- a/GHC/Show.lhs +++ b/GHC/Show.lhs @@ -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 diff --git a/Makefile b/Makefile index 6078fba..cf5917c 100644 --- 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 -- 1.7.10.4