fmt: avoid storing input arguments on pp to help escape analysis
This is part of a series of CLs that aim to reduce how often
interface arguments escape for the print functions in fmt,
such as val here:
func f(val int) {
fmt.Sprintf("%d", val)
}
Prior to this change, arguments immediately escape in doPrintf
because they are stored on the *pp in printArg:
parameter a leaks to <heap> for (*pp).doPrintf with derefs=1:
flow: <heap> ← *a:
from a[argNum] (dot of pointer) at .\print.go:1077:18
from (*pp).printArg(p, a[argNum], rune(c)) (call parameter) at .\print.go:1077:16
parameter arg leaks to <heap> for (*pp).printArg with derefs=0:
flow: <heap> ← arg:
from p.arg = arg (assign) at .\print.go:682:8
The *pp is heap allocated, and the heap cannot point to stack
variables, so the arguments currently cannot be on the stack.
This change instead threads through the input arguments as individual
type any and reflect.Value parameters, rather than storing on the *pp.
After this change, input arguments still escape, but now for
other reasons.
Updates #8618
Updates #62653
Change-Id: I81984daeceb761ce4ce269b150b888950ce2c5d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/524938 Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>