cmd/compile: yet another incorrect recover behavior due to defer a method wrapper #73920
Labels
BugReport
Issues describing a possible bug in the Go implementation.
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
Uh oh!
There was an error while loading. Please reload this page.
Go version
Go 1.20 - Go 1.24
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/D621WgLz6y2
What did you see happen?
The panic is recovered. The program prints "recovered" and exits normally.
What did you expect to see?
Similar to #73917, it is expected to not recover.
This is pretty much the same as #73917, except that it defers a method call with a pointer receiver, whereas it is a value receiver in #73917. I'm filing a separate issue as
Similarly, it panics as expected if inlining is disabled.
Go 1.19 got it right. Go 1.18 and later fail. Bisection points to CL https://go.dev/cl/422235 , which apparently has a lot of effects (I could bisect further with GOEXPERIMENT=unified, but I'll defer it for later). Before that CL, the wrapper
(*S).M
does a tail call to(*T).M
with no inlining. After that CL, the wrapper(*S).M
inlines(*T).M
, while keeping the WRAPPER attribute. Similar to #73916 and #73917, this causes the panic to be treated one frame too deep.It's been the same behavior up to Go 1.24. On tip, it changes, since CL https://go.dev/cl/650455 . Before that CL, tail call is not used for that type of wrappers, because the wrapped function
(*T).M
is inlineable (and actually being inlined). After that CL, we start with emitting an OTAILCALL without the WRAPPER attribute, and later inlines the wrapped function into it, still without the WRAPPER attribute. This corrects the panic stack depth issue (while leaving the issue of the wrapper not being omitted from traceback #73747).The proposed fix for #73747, CL 675916 (as of PS 1), sets the WRAPPER attribute, which would reintroduce this bug.
The text was updated successfully, but these errors were encountered: