mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: only look for struct type when crawling inline body
CL 356254 fixed crawling of embeddable types during inline. However, we are too agressive, since when we call markEmbed for every type seen during inlining function body. That leads to false positive that for a non-embedded type, its unexported methods are also marked inline. Instead, we should only look at struct type that we seen during inlining function body, and calling markEmbed for all of its embedded fields. Fixes #49094 Change-Id: I6ef9a8bf1fc649ec6bf75e4883f6031ec8560ba1 Reviewed-on: https://go-review.googlesource.com/c/go/+/357232 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
23e57e5955
commit
9ff91b9098
@ -217,7 +217,13 @@ func (p *crawler) markInlBody(n *ir.Name) {
|
||||
//
|
||||
// We generate the wrapper for "struct{ t }".M, and inline call
|
||||
// to "struct{ t }".M, which makes "t.M" reachable.
|
||||
p.markEmbed(t)
|
||||
if t.IsStruct() {
|
||||
for _, f := range t.FieldSlice() {
|
||||
if f.Embedded != 0 {
|
||||
p.markEmbed(f.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
11
test/fixedbugs/issue49094.dir/a.go
Normal file
11
test/fixedbugs/issue49094.dir/a.go
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 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 A struct{}
|
||||
|
||||
func (a *A) f() bool {
|
||||
return true
|
||||
}
|
11
test/fixedbugs/issue49094.dir/b.go
Normal file
11
test/fixedbugs/issue49094.dir/b.go
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 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 M(r *a.A) string {
|
||||
return ""
|
||||
}
|
15
test/fixedbugs/issue49094.dir/p.go
Normal file
15
test/fixedbugs/issue49094.dir/p.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2021 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
|
||||
|
||||
import (
|
||||
"./b"
|
||||
)
|
||||
|
||||
type S struct{}
|
||||
|
||||
func (S) M() {
|
||||
b.M(nil)
|
||||
}
|
7
test/fixedbugs/issue49094.go
Normal file
7
test/fixedbugs/issue49094.go
Normal file
@ -0,0 +1,7 @@
|
||||
// compiledir
|
||||
|
||||
// Copyright 2021 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
|
Loading…
x
Reference in New Issue
Block a user