mirror of
https://github.com/golang/go
synced 2024-11-26 11:28:21 -07:00
cmd/compile: fix inlining function has shape in type
CL 395854 made inline pass to not inlining function with shape params, but pass no shape arguments. But it does not consider the case where function has shape params, but passing zero arguments. In this case, the un-safe interface conversion that may be applied to a shape argument can not happen, so it's safe to inline the function. Fixes #52907 Change-Id: Ifa7b23709bb47b97e27dc1bf32343d92683ef783 Reviewed-on: https://go-review.googlesource.com/c/go/+/406176 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
3474cd4eee
commit
19156a5474
@ -714,8 +714,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Don't inline a function fn that has shape parameters, but is passed no shape arg.
|
// Don't inline a function fn that has shape parameters, but is passed no shape arg.
|
||||||
// See comments (1) above, and issue #51909
|
// See comments (1) above, and issue #51909.
|
||||||
inlineable := false
|
inlineable := len(n.Args) == 0 // Function has shape in type, with no arguments can always be inlined.
|
||||||
for _, arg := range n.Args {
|
for _, arg := range n.Args {
|
||||||
if arg.Type().HasShape() {
|
if arg.Type().HasShape() {
|
||||||
inlineable = true
|
inlineable = true
|
||||||
|
19
test/fixedbugs/issue52907.go
Normal file
19
test/fixedbugs/issue52907.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// compile
|
||||||
|
|
||||||
|
// Copyright 2022 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
|
||||||
|
|
||||||
|
func f[T int](t T) {
|
||||||
|
for true {
|
||||||
|
func() {
|
||||||
|
t = func() T { return t }()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f(0)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user