diff options
author | Simon Marlow <marlowsd@gmail.com> | 2009-09-28 12:44:55 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2009-09-28 12:44:55 +0000 |
commit | fd274ffd311d18d6cfb8ecfdf492eff3576620cc (patch) | |
tree | 6138885b58faf216a55ec1c4ad3fd13c2bd25b18 /compiler/cmm | |
parent | b07f975aa0bf4cd638db0003750ccd5e92816bc9 (diff) | |
download | haskell-fd274ffd311d18d6cfb8ecfdf492eff3576620cc.tar.gz |
emitRetUT: cope with arguments overlapping with results (#3546)
In decodeFloat_Int# we have the C-- code:
mp_tmp1 = Sp - WDS(1);
mp_tmp_w = Sp - WDS(2);
/* arguments: F1 = Float# */
arg = F1;
/* Perform the operation */
foreign "C" __decodeFloat_Int(mp_tmp1 "ptr", mp_tmp_w "ptr", arg) [];
/* returns: (Int# (mantissa), Int# (exponent)) */
RET_NN(W_[mp_tmp1], W_[mp_tmp_w]);
Which all looks quite reasonable. The problem is that RET_NN() might
assign the results to the stack (with an unregisterised back end), and
in this case the arguments to RET_NN() refer to the same stack slots
that will be assigned to.
The code generator should do the right thing here, but it wasn't - it
was assuming that it could assign the results sequentially. A 1-line
fix to use emitSimultaneously rather than emitStmts (plus comments).
Diffstat (limited to 'compiler/cmm')
-rw-r--r-- | compiler/cmm/CmmParse.y | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/cmm/CmmParse.y b/compiler/cmm/CmmParse.y index 2c7ffe2845..3cd6be97a2 100644 --- a/compiler/cmm/CmmParse.y +++ b/compiler/cmm/CmmParse.y @@ -978,7 +978,9 @@ emitRetUT :: [(CgRep,CmmExpr)] -> Code emitRetUT args = do tickyUnboxedTupleReturn (length args) -- TICK (sp, stmts) <- pushUnboxedTuple 0 args - emitStmts stmts + emitSimultaneously stmts -- NB. the args might overlap with the stack slots + -- or regs that we assign to, so better use + -- simultaneous assignments here (#3546) when (sp /= 0) $ stmtC (CmmAssign spReg (cmmRegOffW spReg (-sp))) stmtC (CmmJump (entryCode (CmmLoad (cmmRegOffW spReg sp) bWord)) []) -- TODO (when using CPS): emitStmt (CmmReturn (map snd args)) |