1
0
mirror of https://github.com/golang/go synced 2024-11-26 09:08:07 -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:
Cuong Manh Le 2022-05-14 16:15:26 +07:00
parent 3474cd4eee
commit 19156a5474
2 changed files with 21 additions and 2 deletions

View File

@ -714,8 +714,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
}
} else {
// Don't inline a function fn that has shape parameters, but is passed no shape arg.
// See comments (1) above, and issue #51909
inlineable := false
// See comments (1) above, and issue #51909.
inlineable := len(n.Args) == 0 // Function has shape in type, with no arguments can always be inlined.
for _, arg := range n.Args {
if arg.Type().HasShape() {
inlineable = true

View 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)
}