Skip to content

Commit

Permalink
Merge pull request #530 from MatthewFluet/allocate-vars-handler-offse…
Browse files Browse the repository at this point in the history
…t-bug

Fix `Backend` bug in allocation of `handlerOffset` and `handlerArgs`
  • Loading branch information
MatthewFluet authored Nov 9, 2023
2 parents 115f6f2 + 823ec5f commit 04d7690
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions mlton/backend/allocate-variables.fun
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* Copyright (C) 2017,2019,2022 Matthew Fluet.
(* Copyright (C) 2017,2019,2022-2023 Matthew Fluet.
* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
Expand Down Expand Up @@ -102,7 +102,9 @@ structure Allocation:
| (a1 as {offset = offset1, size = size1})::(a2 as {offset = offset2, size = size2})::alloc =>
if Bytes.equals (Bytes.+ (offset1, size1), offset2)
then loop ({offset = offset1, size = Bytes.+ (size1, size2)}::alloc, ac)
else loop (a2::alloc, a1::ac)
else if Bytes.> (Bytes.+ (offset1, size1), offset2)
then Error.bug "AllocateVariables.Stack.new"
else loop (a2::alloc, a1::ac)
in
T (loop (Array.toList a, []))
end
Expand Down Expand Up @@ -461,8 +463,8 @@ fun allocate {function = f: Rssa.Function.t,
*)
val (stack, {offset = linkOffset, ...}) =
Allocation.Stack.get (stack, Type.exnStack ())
val (_, {offset = handlerOffset, ...}) =
Allocation.Stack.get (stack, Type.label (Label.newNoname ()))
val handlerTy = Type.label (Label.newNoname ())
val handlerOffset = Type.align (handlerTy, Allocation.Stack.size stack)
val handlerArgsOffset =
Bytes.align
(Bytes.+ (handlerOffset, Runtime.labelSize ()),
Expand All @@ -476,6 +478,17 @@ fun allocate {function = f: Rssa.Function.t,
(paramOffsets args, maxSize, fn ({offset, ty, ...}, maxSize) =>
Bytes.max (maxSize, Bytes.+ (offset, Type.bytes ty))))
val handlerOffset = Bytes.- (handlerArgsOffset, Runtime.labelSize ())
val () =
Control.diagnostic
(fn () =>
let open Layout
in
record
[("handlerArgsOffset", Bytes.layout handlerArgsOffset),
("handlerArgsSize", Bytes.layout handlerArgsSize),
("handlerOffset", Bytes.layout handlerOffset),
("linkOffset", Bytes.layout linkOffset)]
end)
in
SOME {handlerArgsOffset = handlerArgsOffset,
handlerArgsSize = handlerArgsSize,
Expand Down

0 comments on commit 04d7690

Please sign in to comment.