From: Cuong Manh Le Date: Sat, 14 May 2022 09:15:26 +0000 (+0700) Subject: cmd/compile: fix inlining function has shape in type X-Git-Tag: go1.19beta1~237 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=19156a54741d4f353c9e8e0860197ca95a6ee6ca;p=gostls13.git 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 Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 7c45f1443b..ff2780de82 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -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 diff --git a/test/fixedbugs/issue52907.go b/test/fixedbugs/issue52907.go new file mode 100644 index 0000000000..776be7f280 --- /dev/null +++ b/test/fixedbugs/issue52907.go @@ -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) +}