0
1
mirror of https://github.com/golang/go synced 2025-04-22 01:29:12 +00:00
Files
go/test/fixedbugs/issue58341.go
Cuong Manh Le 2d01f3695b [release-branch.go1.20] cmd/compile: fix wrong escape analysis for go/defer generic calls
For go/defer calls like "defer f(x, y)", the compiler rewrites it to:

	x1, y1 := x, y
	defer func() { f(x1, y1) }()

However, if "f" needs runtime type information, the "RType" field will
refer to the outer ".dict" param, causing wrong liveness analysis.

To fix this, if "f" refers to outer ".dict", the dict param will be
copied to an autotmp, and "f" will refer to this autotmp instead.

Fixes #58467

Change-Id: I238b6e75441442b5540d39bc818205398e80c94d
Reviewed-on: https://go-review.googlesource.com/c/go/+/466035
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/467935
Reviewed-by: Michael Pratt <mpratt@google.com>
2023-02-15 21:46:55 +00:00

31 lines
471 B
Go

// compile
// Copyright 2023 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 p
type S[T comparable] struct {
m map[T]T
}
func (s S[T]) M1(node T) {
defer delete(s.m, node)
}
func (s S[T]) M2(node T) {
defer func() {
delete(s.m, node)
}()
}
func (s S[T]) M3(node T) {
defer f(s.m, node)
}
//go:noinline
func f[T comparable](map[T]T, T) {}
var _ = S[int]{}