From: Matthew Dempsky Date: Fri, 30 Oct 2020 17:36:31 +0000 (-0700) Subject: cmd/compile: fix reassignVisitor X-Git-Tag: go1.16beta1~385 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7191f1136b1526703c5af7fc04ff948e3a6c26b9;p=gostls13.git 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 Run-TryBot: Matthew Dempsky Reviewed-by: Cuong Manh Le Reviewed-by: David Chase TryBot-Result: Go Bot --- diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index 5b58908299..8a5c6d8666 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -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 diff --git a/test/fixedbugs/issue42284.dir/a.go b/test/fixedbugs/issue42284.dir/a.go new file mode 100644 index 0000000000..e1271af32d --- /dev/null +++ b/test/fixedbugs/issue42284.dir/a.go @@ -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() +} diff --git a/test/fixedbugs/issue42284.dir/b.go b/test/fixedbugs/issue42284.dir/b.go new file mode 100644 index 0000000000..3305166db0 --- /dev/null +++ b/test/fixedbugs/issue42284.dir/b.go @@ -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() +} diff --git a/test/fixedbugs/issue42284.go b/test/fixedbugs/issue42284.go new file mode 100644 index 0000000000..e5d6173f5c --- /dev/null +++ b/test/fixedbugs/issue42284.go @@ -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