]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssagen: fix race added in CL 510539
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Aug 2023 21:18:06 +0000 (14:18 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 17 Aug 2023 21:51:00 +0000 (21:51 +0000)
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 <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/ssagen/ssa.go

index 25e93b531d55ebe649192633404fc57a2d13c758..fe4a24200229094fd10ebc3a41110cda009e77f7 100644 (file)
@@ -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