Skip to content

go.types/go/ssa: should not use changetype to form unbound method references #7839

@pcc

Description

@pcc
What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

Create a file with the following contents (extracted from ddd.go in the go test suite):

package main

type T struct {}

func (*T) Sum(args ...int) int { return 0 }

type U struct {
        *T
}

func main() {
        U.Sum(U{}, 1, 3, 5, 1)
}

2. Run ssadump -build=F over the program.

What happened?

The changetype instruction is used to produce a value for the unbound method reference.

t0 = changetype func(U, args ...int) int <- func(args ...int) int ((U).Sum) func(U,
args ...int)

What should have happened instead?

The changetype instruction should not be used, as the conversion from func (U) (...int)
to func(U, ...int) is not necessarily value preserving: it is possible that the former
type uses a different calling convention than the latter. Instead, a thunk should be
generated.

Please provide any additional information below.

This is true for gccgo for example, which passes receivers by reference so that method
function pointers can be shared between the value type's method table and the pointer
type's method table.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions