mirror of
https://github.com/golang/go
synced 2025-04-12 00:29:42 +00:00
cmd/compile: fix reassignVisitor
reassignVisitor was short-circuiting on assignment statements after checking the LHS, but there might be further assignment statements nested within the RHS expressions. Fixes #42284. Change-Id: I175eef87513b973ed5ebe6a6527adb9766dde6cf Reviewed-on: https://go-review.googlesource.com/c/go/+/266618 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
@ -839,14 +839,12 @@ func (v *reassignVisitor) visit(n *Node) *Node {
|
||||
if n.Left == v.name && n != v.name.Name.Defn {
|
||||
return n
|
||||
}
|
||||
return nil
|
||||
case OAS2, OAS2FUNC, OAS2MAPR, OAS2DOTTYPE:
|
||||
for _, p := range n.List.Slice() {
|
||||
if p == v.name && n != v.name.Name.Defn {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if a := v.visit(n.Left); a != nil {
|
||||
return a
|
||||
|
23
test/fixedbugs/issue42284.dir/a.go
Normal file
23
test/fixedbugs/issue42284.dir/a.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2020 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 a
|
||||
|
||||
type I interface{ M() }
|
||||
type T int
|
||||
|
||||
func (T) M() {} // ERROR "can inline T.M"
|
||||
|
||||
func F(i I) I { // ERROR "can inline F" "leaking param: i to result ~r1 level=0"
|
||||
i = nil
|
||||
return i
|
||||
}
|
||||
|
||||
func g() { // ERROR "can inline g"
|
||||
// BAD: T(0) could be stack allocated.
|
||||
i := F(T(0)) // ERROR "inlining call to F" "T\(0\) escapes to heap"
|
||||
|
||||
// Testing that we do NOT devirtualize here:
|
||||
i.M()
|
||||
}
|
15
test/fixedbugs/issue42284.dir/b.go
Normal file
15
test/fixedbugs/issue42284.dir/b.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2020 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 b
|
||||
|
||||
import "./a"
|
||||
|
||||
func g() { // ERROR "can inline g"
|
||||
// BAD: T(0) could be stack allocated.
|
||||
i := a.F(a.T(0)) // ERROR "inlining call to a.F" "a.T\(0\) escapes to heap"
|
||||
|
||||
// Testing that we do NOT devirtualize here:
|
||||
i.M()
|
||||
}
|
7
test/fixedbugs/issue42284.go
Normal file
7
test/fixedbugs/issue42284.go
Normal file
@ -0,0 +1,7 @@
|
||||
// errorcheckdir -0 -m
|
||||
|
||||
// Copyright 2020 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 ignored
|
Reference in New Issue
Block a user