From 639f6f7e789ffbafd3d6f4327dbc10586e8163db Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 17 Aug 2023 14:18:06 -0700 Subject: [PATCH] cmd/compile/internal/ssagen: fix race added in CL 510539 The ssagen pass runs concurrently, so it's not safe to mutate global variables like this. Instead, turn it into a constant and add an assertion that the constant has the correct value. Fixes #62095. Change-Id: Ia7f07e33582564892d194153ac3d8759429fc9ac Reviewed-on: https://go-review.googlesource.com/c/go/+/520598 TryBot-Result: Gopher Robot Run-TryBot: Matthew Dempsky Reviewed-by: Bryan Mills Reviewed-by: Keith Randall Auto-Submit: Matthew Dempsky --- src/cmd/compile/internal/ssagen/ssa.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 25e93b531d..fe4a242002 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -8086,7 +8086,7 @@ func max8(a, b int8) int8 { return b } -var deferStructFnField = -1 +const deferStructFnField = 4 // deferstruct makes a runtime._defer structure. func deferstruct() *types.Type { @@ -8111,14 +8111,8 @@ func deferstruct() *types.Type { makefield("link", types.Types[types.TUINTPTR]), makefield("head", types.Types[types.TUINTPTR]), } - for i, f := range fields { - if f.Sym.Name == "fn" { - deferStructFnField = i - break - } - } - if deferStructFnField < 0 { - base.Fatalf("deferstruct has no fn field") + if name := fields[deferStructFnField].Sym.Name; name != "fn" { + base.Fatalf("deferStructFnField is %q, not fn", name) } // build struct holding the above fields -- 2.48.1