runtime: AddCleanup does not panic if arg equals ptr #71316
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FixPending
Issues that have a fix which has not yet been reviewed or submitted.
NeedsFix
The path to resolution is known, but the work has not been done.
release-blocker
Milestone
Go version
tip (go1.24-40b3c0e58a Fri Jan 17 08:40:47 2025 -0800 darwin/arm64)
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/2SwFBThx4xJ?v=gotip
In particular,
runtime.AddCleanup(t, func(a *T) { println("cleanup", a.x); ch <- 1 }, t)
where the first and third arguments are equal.What did you see happen?
It does not panic at the
AddCleanup
call. The cleanup never runs.What did you expect to see?
runtime.AddCleanup
is documented that it panics if arg is equal to ptr. E.g.the code above should panic at the
AddCleanup
call.The source code of AddCleanup includes
But it is checking the address of arg not equal to ptr, not arg itself. And &arg cannot equal to ptr, because it's the address of an argument of a new frame. So this condition can never trigger. Also, it is a throw, not a panic as documented.
Is this what the TODO is for?
cc @cagedmantis @mknyszek
The text was updated successfully, but these errors were encountered: