-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Milestone
Description
What version of Go are you using (go version
)?
tip (ca7c12d)
Does this issue reproduce with the latest release?
No, not with Go 1.11
What operating system and processor architecture are you using (go env
)?
linux/amd64
What did you do?
https://play.golang.org/p/HIJtff_t5Wh
package main
import "runtime"
type P string
func (p P) String() string {
runtime.GC()
runtime.GC()
runtime.GC()
zzz := "ZZZ"
sink = zzz
return string(p)
}
var sink interface{}
func main() {
defer func() {
panic(P("YYY"))
}()
panic(P("XXX"))
}
What did you expect to see?
With Go 1.11, this program panics with
panic: XXX
panic: YYY
which looks correct to me.
What did you see instead?
With tip, this program panics with
panic: XXX
panic: ZZZ
The "YYY" panic message is clobbered.
In runtime.gopanic, the _panic
struct p
is stack allocated and referenced from gp._panic
. With stack objects, the stack variable p
is dead at the point the panic message is printed (preprintpanics at https://go.googlesource.com/go/+/master/src/runtime/panic.go#563). gp._panic
points to p
, but stack scan doesn't look at gp
. So whatever p
points to may be collected and clobbered. We need to keep it alive.
Will send a CL soon.