Skip to content

Commit cbb9cd0

Browse files
committed
cmd/compile: ensure FuncForPC works on closures that start with NOPs
A 0-sized no-op shouldn't prevent us from detecting that the first instruction is from an inlined callee. Update #58300 Change-Id: Ic5f6ed108c54a32c05e9b2264b516f2cc17e4619 Reviewed-on: https://go-review.googlesource.com/c/go/+/467977 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 5e74bc1 commit cbb9cd0

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7171,7 +7171,7 @@ func genssa(f *ssa.Func, pp *objw.Progs) {
71717171
// This ensures that runtime.FuncForPC(uintptr(reflect.ValueOf(fn).Pointer())).Name()
71727172
// returns the right answer. See issue 58300.
71737173
for p := pp.Text; p != nil; p = p.Link {
7174-
if p.As == obj.AFUNCDATA || p.As == obj.APCDATA || p.As == obj.ATEXT {
7174+
if p.As == obj.AFUNCDATA || p.As == obj.APCDATA || p.As == obj.ATEXT || p.As == obj.ANOP {
71757175
continue
71767176
}
71777177
if base.Ctxt.PosTable.Pos(p.Pos).Base().InliningIndex() >= 0 {

test/fixedbugs/issue58300b.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// run
2+
3+
// Copyright 2023 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import (
10+
"reflect"
11+
"runtime"
12+
)
13+
14+
type T struct {
15+
a, b int
16+
}
17+
18+
func f(t *T) int {
19+
if t != nil {
20+
return t.b
21+
}
22+
return 0
23+
}
24+
25+
func g(t *T) int {
26+
return f(t) + 5
27+
}
28+
29+
func main() {
30+
x(f)
31+
x(g)
32+
}
33+
func x(v any) {
34+
println(runtime.FuncForPC(reflect.ValueOf(v).Pointer()).Name())
35+
}

test/fixedbugs/issue58300b.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main.f
2+
main.g

0 commit comments

Comments
 (0)