cmd/compile: sync/atomic.SwapPointer arguments escape for the wrong reason #15283
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
In the implementation of sync/atomic.SwapPointer (which is in runtime/atomic_pointer.go), there's nothing that causes the "new" argument to escape, even though it needs to (because you could be swapping it in to a global). The compiler agrees:
However, you can't actually tickle this. For example, in principle the following program should sneak the address of stack variable y into a global variable:
But it doesn't!
This happens to work right now, but for the wrong reason: because SwapPointer is defined in the runtime and we use a "go:linkname" comment to expose it from sync/atomic, there's no escape information at all when the test program calls SwapPointer (hence the "passed to function[unknown]"), so the compiler conservatively assumes everything escapes. (In fact, the first argument doesn't have to escape and we have annotations in the runtime to that effect, but they never make it through.)
This all seems very fragile.
/cc @dr2chase @randall77
The text was updated successfully, but these errors were encountered: