[commit: ghc] ghc-7.10: UNREG: fix pprHexVal to emit zeros (#10518) (fa942e6)
git at git.haskell.org
git at git.haskell.org
Mon Jun 15 14:22:17 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.10
Link : http://ghc.haskell.org/trac/ghc/changeset/fa942e67727c7bb06199055d16d3ae16642181e7/ghc
>---------------------------------------------------------------
commit fa942e67727c7bb06199055d16d3ae16642181e7
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date: Sun Jun 14 16:42:03 2015 +0100
UNREG: fix pprHexVal to emit zeros (#10518)
jakzale on #ghc reported a build failure
when ported GHC on a new target.
The code 'pprHexVal (2^32) W32' emits '0xU'
which is invalid C.
I've introduced bug in
43f1b2ecd1960fa7377cf55a2b97c66059a701ef
when added literal truncation. That truncation
is a new source of zeros.
Signed-off-by: Sergei Trofimovich <siarheit at google.com>
Test Plan: added test and tested on UNREG ghc
Reviewers: austin
Reviewed By: austin
Subscribers: thomie, bgamari
Differential Revision: https://phabricator.haskell.org/D987
GHC Trac Issues: #10518
(cherry picked from commit a5084557b0b30faf3f89386ee6ee5a308dae51b1)
>---------------------------------------------------------------
fa942e67727c7bb06199055d16d3ae16642181e7
compiler/cmm/PprC.hs | 5 +++--
testsuite/tests/codeGen/should_compile/T10518.cmm | 5 +++++
testsuite/tests/codeGen/should_compile/all.T | 1 +
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
index a2c3abf..3c4c379 100644
--- a/compiler/cmm/PprC.hs
+++ b/compiler/cmm/PprC.hs
@@ -1219,7 +1219,6 @@ commafy xs = hsep $ punctuate comma xs
-- Print in C hex format: 0x13fa
pprHexVal :: Integer -> Width -> SDoc
-pprHexVal 0 _ = ptext (sLit "0x0")
pprHexVal w rep
| w < 0 = parens (char '-' <>
ptext (sLit "0x") <> intToDoc (-w) <> repsuffix rep)
@@ -1239,7 +1238,9 @@ pprHexVal w rep
repsuffix _ = char 'U'
intToDoc :: Integer -> SDoc
- intToDoc i = go (truncInt i)
+ intToDoc i = case truncInt i of
+ 0 -> char '0'
+ v -> go v
-- We need to truncate value as Cmm backend does not drop
-- redundant bits to ease handling of negative values.
diff --git a/testsuite/tests/codeGen/should_compile/T10518.cmm b/testsuite/tests/codeGen/should_compile/T10518.cmm
new file mode 100644
index 0000000..966cd4a
--- /dev/null
+++ b/testsuite/tests/codeGen/should_compile/T10518.cmm
@@ -0,0 +1,5 @@
+foo() {
+ bits64 a;
+ a = 0x10000000000000000; // overflows 64 bits
+ return (a);
+}
diff --git a/testsuite/tests/codeGen/should_compile/all.T b/testsuite/tests/codeGen/should_compile/all.T
index e06cead..c78f9ac 100644
--- a/testsuite/tests/codeGen/should_compile/all.T
+++ b/testsuite/tests/codeGen/should_compile/all.T
@@ -30,3 +30,4 @@ test('debug', extra_clean(['debug.cmm']),
run_command,
['$MAKE -s --no-print-directory debug'])
test('T9964', normal, compile, ['-O'])
+test('T10518', [cmm_src], compile, [''])
More information about the ghc-commits
mailing list