Registers above R8 corrupt when called through prim import
I write a cmm function:
primbug
{
foreign "C" printf("%d %d %d %d %d %d %d %d %d\n", R1, R2, R3, R4, R5, R6, R7, R8, R9);
RET_N(R9);
}
and a binding to it in Haskell:
foreign import prim "primbug" primbug :: Int# -> Int# -> Int# -> Int#
-> Int# -> Int# -> Int# -> Int#
-> Int#
-> Int#
-- This should resemble id
bug :: Int -> Int
bug (I# i) = I# (primbug 0# 111# 222# 333# 444# 555# 666# 777# i)
main = print (bug 888)
and the program outputs:
0 111 222 333 444 555 666 777 0
0
The contents of R9 have been lost somehow! The result of this corruption isn't always 0, if that helps track it down: in my more complicated use case, I'm getting smallish numbers (two hex digits) instead of a legitimate pointer.
I'm attaching a small cabal package to help reproduce it, because it's a pain to build.
Trac metadata
Trac field | Value |
---|---|
Version | 7.2.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |