]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: ensure first instruction in a function is not inlined
authorKeith Randall <khr@golang.org>
Fri, 3 Feb 2023 17:59:55 +0000 (09:59 -0800)
committerKeith Randall <khr@golang.org>
Mon, 6 Feb 2023 20:39:54 +0000 (20:39 +0000)
commit103f37497f2927eeb510789f63fe2a0319b6a49a
treea8dfae8a6641fbf10815ed7721990faf23090296
parent55bd193575152ea09db3a0bd33f9dda49725d8f4
cmd/compile: ensure first instruction in a function is not inlined

People are using this to get the name of the function from a function type:

runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()

Unfortunately, this technique falls down when the first instruction
of the function is from an inlined callee. Then the expression above
gets you the name of the inlined function instead of the function itself.

To fix this, ensure that the first instruction is never from an inlinee.
Normally functions have prologs so those are already fine. In just the
cases where a function is a leaf with no local variables, and an instruction
from an inlinee appears first in the prog list, add a nop at the start
of the function to hold a non-inlined position.

Consider the nop a "mini-prolog" for leaf functions.

Fixes #58300

Change-Id: Ie37092f4ac3167fe8e5ef4a2207b14abc1786897
Reviewed-on: https://go-review.googlesource.com/c/go/+/465076
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssagen/ssa.go
test/fixedbugs/issue58300.go [new file with mode: 0644]
test/fixedbugs/issue58300.out [new file with mode: 0644]