Commit 412af8c2 authored by Simon Marlow's avatar Simon Marlow
Browse files

Foreign calls can clobber heap & stack memory too

We were making an aggressive assumption that foreign calls cannot
clobber heap or stack memory, which for the majority of foreign calls
is true, but we violate the assumption in the implementation of
primops in the RTS.  This was causing crashes in some STM tests.
parent 49108c33
......@@ -464,8 +464,8 @@ conflicts dflags (r, rhs, addr) node
-- foreign call. See Note [foreign calls clobber GlobalRegs].
| CmmUnsafeForeignCall{} <- node, anyCallerSavesRegs dflags rhs = True
-- (5) foreign calls clobber memory, but not heap/stack memory
| CmmUnsafeForeignCall{} <- node, AnyMem <- addr = True
-- (5) foreign calls clobber heap: see Note [foreign calls clobber heap]
| CmmUnsafeForeignCall{} <- node, memConflicts addr AnyMem = True
-- (6) native calls clobber any memory
| CmmCall{} <- node, memConflicts addr AnyMem = True
......@@ -523,6 +523,21 @@ data AbsMem
-- that was written in the same basic block. To take advantage of
-- non-aliasing of heap memory we will have to be more clever.
-- Note [foreign calls clobber]
--
-- It is tempting to say that foreign calls clobber only
-- non-heap/stack memory, but unfortunately we break this invariant in
-- the RTS. For example, in stg_catch_retry_frame we call
-- stmCommitNestedTransaction() which modifies the contents of the
-- TRec it is passed (this actually caused incorrect code to be
-- generated).
--
-- Since the invariant is true for the majority of foreign calls,
-- perhaps we ought to have a special annotation for calls that can
-- modify heap/stack memory. For now we just use the conservative
-- definition here.
bothMems :: AbsMem -> AbsMem -> AbsMem
bothMems NoMem x = x
bothMems x NoMem = x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment