Closed
Description
package main
import (
"reflect"
"runtime"
)
func f(n int) int {
return n % 2
}
func g(n int) int {
return f(n)
}
func name(fn any) (res string) {
return runtime.FuncForPC(uintptr(reflect.ValueOf(fn).Pointer())).Name()
}
func main() {
println(name(f))
println(name(g))
}
Prints
main.f
main.f
where it should print
main.f
main.g
This happens because the first instruction of g
is an instruction inlined from f
.
This came up recently because the scheduler change https://go-review.googlesource.com/c/go/+/270940 subtly changes the ordering, and line numbering, of assembly instructions at the start of functions.