mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: add missing OASOP case in mayModifyPkgVar
CL 395541 made staticopy safe, stop applying the optimization once seeing an expression that may modify global variables. However, it misses the case for OASOP expression, causing the static init mis-recognizes the modification and think it's safe. Fixing this by adding missing OASOP case. Fixes #66585 Change-Id: I603cec018d3b5a09825c14e1f066a0e16f8bde23 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/575216 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
973befe714
commit
5038ce82b6
@ -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) {
|
||||
|
25
test/fixedbugs/issue66585.go
Normal file
25
test/fixedbugs/issue66585.go
Normal file
@ -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")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user