mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add //go:uintptrkeepalive
This CL exports the existing ir.UintptrKeepAlive via the new directive //go:uintptrkeepalive. This makes the compiler insert KeepAlives for pointers converted to uintptr in calls, keeping them alive for the duration of the call. //go:uintptrkeepalive requires //go:nosplit, as stack growth can't handle these arguments (it cannot know which are pointers). We currently check this on the immediate function, but the actual restriction applies to all transitive calls. The existing //go:uintptrescapes is an extension of //go:uintptrkeepalive which forces pointers to escape to the heap, thus eliminating the stack growth issue. This pragma is limited to the standard library. For #51087 Change-Id: If9a19d484d3561b4219e5539b70c11a3cc09391e Reviewed-on: https://go-review.googlesource.com/c/go/+/388095 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
e25a5ce120
commit
342b495301
11 changed files with 128 additions and 32 deletions
|
|
@ -120,6 +120,17 @@ func CanInline(fn *ir.Func) {
|
|||
return
|
||||
}
|
||||
|
||||
// If marked as "go:uintptrkeepalive", don't inline, since the
|
||||
// keep alive information is lost during inlining.
|
||||
//
|
||||
// TODO(prattmic): This is handled on calls during escape analysis,
|
||||
// which is after inlining. Move prior to inlining so the keep-alive is
|
||||
// maintained after inlining.
|
||||
if fn.Pragma&ir.UintptrKeepAlive != 0 {
|
||||
reason = "marked as having a keep-alive uintptr argument"
|
||||
return
|
||||
}
|
||||
|
||||
// If marked as "go:uintptrescapes", don't inline, since the
|
||||
// escape information is lost during inlining.
|
||||
if fn.Pragma&ir.UintptrEscapes != 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue