Skip to content

cmd/compile: "Open defer" of method call miscompiled at tip #45062

@dr2chase

Description

@dr2chase

What version of Go are you using (go version)?

This is for Go 1.17 development, the bug appears at https://go-review.googlesource.com/c/go/+/293393

Does this issue reproduce with the latest release?

It is not seen in 1.16.

What did you do?

Playground shows expected behavior.
https://play.golang.org/p/EVQdmu7Z5bH

package main

func main() {
	var x, y, z int = -1, -2, -3
	F(x, y, z)
}

//go:noinline
func F(x, y, z int) {
	defer i.M(x, y, z)
	defer func() { recover() }()
	panic("XXX")
}

type T int
func (t *T) M(x, y, z int) { println(t, *t, x, y, z) }

var t T = 42

type I interface{ M(x, y, z int) }
var i I = &t

What did you see instead?

unexpected fault address 0xffffffffffffffff
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xffffffffffffffff pc=0x105f046]

goroutine 1 [running]:
runtime.throw(0x10749df, 0x5)
	/Users/drchase/work/go/src/runtime/panic.go:1126 +0x74 fp=0xc000032540 sp=0xc000032510 pc=0x102f614
runtime.sigpanic()
	/Users/drchase/work/go/src/runtime/signal_unix.go:742 +0x3e5 fp=0xc0000325a0 sp=0xc000032540 pc=0x1045145
main.(*T).M(0xffffffffffffffff, 0xfffffffffffffffe, 0xfffffffffffffffd, 0x0)
	/Users/drchase/work/tmp/g3b.go:16 +0x26 fp=0xc0000325c0 sp=0xc0000325a0 pc=0x105f046
runtime.call32(0x0, 0x108b4e0, 0xc000058048, 0x2000000020, 0x20, 0xc000032620)
	/Users/drchase/work/go/src/runtime/asm_amd64.s:604 +0x49 fp=0xc0000325f0 sp=0xc0000325c0 pc=0x105a169
runtime.reflectcallSave(0x0, 0x108b4e0, 0xc000058048, 0x20)
	/Users/drchase/work/go/src/runtime/panic.go:884 +0x66 fp=0xc000032630 sp=0xc0000325f0 pc=0x102eba6
runtime.runOpenDeferFrame(0xc000000180, 0xc000058000, 0x1066420)
	/Users/drchase/work/go/src/runtime/panic.go:852 +0x625 fp=0xc0000326b8 sp=0xc000032630 pc=0x102e885
runtime.deferreturn(0x1066420)
	/Users/drchase/work/go/src/runtime/panic.go:536 +0x135 fp=0xc000032708 sp=0xc0000326b8 pc=0x102d9f5
main.F(0xffffffffffffffff, 0xfffffffffffffffe, 0xfffffffffffffffd)
	/Users/drchase/work/tmp/bug.go:12 +0xab fp=0xc000032760 sp=0xc000032708 pc=0x105f00b
main.main()
	/Users/drchase/work/tmp/bug.go:5 +0x3c fp=0xc000032788 sp=0xc000032760 pc=0x105ef3c
runtime.main()
	/Users/drchase/work/go/src/runtime/proc.go:225 +0x256 fp=0xc0000327e0 sp=0xc000032788 pc=0x10321b6
runtime.goexit()
	/Users/drchase/work/go/src/runtime/asm_amd64.s:1448 +0x1 fp=0xc0000327e8 sp=0xc0000327e0 pc=0x105bca1

Root cause is failure to account for receiver at index zero when processing parameters, a CL is in the works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions