diff options
-rw-r--r-- | src/cmd/compile/internal/staticinit/sched.go | 6 | ||||
-rw-r--r-- | test/fixedbugs/issue66585.go | 25 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go index 1f119920e9..7317ed1fec 100644 --- a/src/cmd/compile/internal/staticinit/sched.go +++ b/src/cmd/compile/internal/staticinit/sched.go @@ -899,6 +899,12 @@ func mayModifyPkgVar(n ir.Node) bool { case ir.OAPPEND, ir.OCLEAR, ir.OCOPY: return true // could mutate a global array + case ir.OASOP: + n := n.(*ir.AssignOpStmt) + if !safeLHS(n.X) { + return true + } + case ir.OAS: n := n.(*ir.AssignStmt) if !safeLHS(n.X) { diff --git a/test/fixedbugs/issue66585.go b/test/fixedbugs/issue66585.go new file mode 100644 index 0000000000..fdadf59d63 --- /dev/null +++ b/test/fixedbugs/issue66585.go @@ -0,0 +1,25 @@ +// run + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var x = 0 +var a = foo() +var b = x + +func foo() int { + x++ + return x +} + +func main() { + if a != 1 { + panic("unexpected a value") + } + if b != 1 { + panic("unexpected b value") + } +} |