From 25ec110e5164d43ae8a971928d576a94fb61862f Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 11 Aug 2023 09:29:30 -0700 Subject: [PATCH] [release-branch.go1.21] cmd/compile: ensure empty blocks in write barriers are marked unpreemptible Fixes #61958 Change-Id: I242ab77ad2f1ea1dad2d14ef756fa92f9378429f Reviewed-on: https://go-review.googlesource.com/c/go/+/518755 Reviewed-by: Keith Randall Auto-Submit: Dmitri Shuralyov TryBot-Result: Gopher Robot Run-TryBot: Keith Randall Reviewed-by: David Chase --- src/cmd/compile/internal/ssagen/ssa.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 678e1ebc11..597a196ba8 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -7083,8 +7083,21 @@ func genssa(f *ssa.Func, pp *objw.Progs) { // for an empty block this will be used for its control // instruction. We won't use the actual liveness map on a // control instruction. Just mark it something that is - // preemptible, unless this function is "all unsafe". - s.pp.NextLive = objw.LivenessIndex{StackMapIndex: -1, IsUnsafePoint: liveness.IsUnsafe(f)} + // preemptible, unless this function is "all unsafe", or + // the empty block is in a write barrier. + unsafe := liveness.IsUnsafe(f) + if b.Kind == ssa.BlockPlain { + // Empty blocks that are part of write barriers need + // to have their control instructions marked unsafe. + c := b.Succs[0].Block() + for _, v := range c.Values { + if v.Op == ssa.OpWBend { + unsafe = true + break + } + } + } + s.pp.NextLive = objw.LivenessIndex{StackMapIndex: -1, IsUnsafePoint: unsafe} if idx, ok := argLiveBlockMap[b.ID]; ok && idx != argLiveIdx { argLiveIdx = idx -- 2.50.0