Skip to content

gccgo: double evaluation in interface field expression #26248

@cherrymui

Description

@cherrymui

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

go version go1.10.3 gccgo (GCC) 9.0.0 20180622 (experimental) linux/amd64

What did you do?

package main
  
type I interface{
        M()
}

type T struct{}
func (T) M() {}

//go:noinline
func G() I {
        println("XXX")
        return T{}
}

//go:noinline
func G2(interface{}) {}

//go:noinline
func F() {
        x := G().M
        G2(x)
}

func main() {
        F()
}

What did you expect to see?

$ go run -compiler=gc i.go
XXX

What did you see instead?

$ go run -compiler=gccgo i.go
XXX
XXX

It generates two calls to G in F, one in nil check, one in constructing the func value G().M.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions