Problem in C Code Generator, with patch
Christopher Vollick
0 at psycoti.ca
Sat Jan 26 23:18:09 CET 2013
Hey guys!
So, I was working on some cross-compiling, and found a bug
(http://hackage.haskell.org/trac/ghc/ticket/7620)
Eventually I found that the issue was with C CodeGen in general, and had
nothing to do with ARM.
I've attached the patch there, but it may be only part of a bigger
problem.
The rough problem came from two things:
1) -(-128 :: Int8) => -128
You can't negate the smallest int in an integer space because of how
2s compliment works. There aren't enough bits to store +128.
2) We have a number of operations that transform:
| i < 0 = a + i => a - (negative i)
And
| i < 0 = a - i => a + (negative i)
And the assumption is that any integer can be negated, but that's not
true in exactly one case.
So, for example, it could turn
thing+-128
into
thing--128
Which is not valid C.
That (but for Int32) was what I was seeing, and causing me trouble
building integer simple.
So, that was the bug I had encountered, and I don't know how the GHC
code works, I just trawled through until I found the line that was
causing me trouble, but I just figured I'd remind people that not every
integer can be negated, in case the same mistake is being done in other
places.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-De-Optimized-RegOff.patch
Type: text/x-diff
Size: 1574 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130126/3fb093f6/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130126/3fb093f6/attachment.pgp>
More information about the ghc-devs
mailing list