Skip to content

cmd/compile: wrong liveness map #18860

Closed
Closed
@randall77

Description

@randall77
func f(p, q *int) (r *int) {
	r = p
	defer func() {
		recover()
	}()
	g()
	r = q
	return
}
func g()

At the call to g, r should be marked as live. It isn't.

> go tool compile -live ~/go/tmp3.go
tmp3.go:3: live at entry to f: p q
tmp3.go:7: live at call to deferproc: q r
tmp3.go:8: live at call to g: q                   <- r is live here
tmp3.go:10: live at call to deferreturn: r
tmp3.go:7: live at call to deferreturn: r

Any defer makes all of the output args live at any (possibly panicing) call.
Found using the dead-slot clobberer, https://go-review.googlesource.com/c/23924/
Seems to be around for a while, at least 1.6.
I'm not sure why the dead-slot clobberer didn't find this before.

(Note to self: original detection from encoding/gob/encoder_test.go:encodeAndRecover.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions