Skip to content

cmd/compile: incorrect escape analysis after transitive inlining across packages #11053

Closed
@neild

Description

@neild

This can probably be reduced further, but the following works. The example below shows the value changing to 0, but I've observed it being filled with other garbage values as well.

I'm guessing the value is being incorrectly GCd.

package p

func Int32(i int32) *int32 {
        return &i
}
package p_test

import (
        "fmt"
        "testing"

        "p"
)

type I interface {
        Add(out *P)
}

type P struct {
        V *int32
}

type T struct{}

func (T) Add(out *P) {
        out.V = p.Int32(42)
}

func F(s I) interface{} {
        out := &P{}
        s.Add(out)
        return out
}

func TestP(t *testing.T) {
        var s T
        resp := F(s).(*P)
        fmt.Sprint(new(int32)) // this line is necessary
        if got, want := *resp.V, int32(42); got != want {
                t.Errorf("got %v, want %v", got, want)
        }
}
$ go version
go version go1.4.2 linux/amd64
$ go test
PASS

$ go version
go version devel +1e48683 Wed Jun 3 22:28:06 2015 +0000 linux/amd64
$ /tmp/g/bin/go test
--- FAIL: TestP (0.00s)
        p_test.go:35: got 0, want 42
FAIL

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions