Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
neild opened this issue Jun 4, 2015 · 4 comments
Closed
Milestone

Comments

@neild
Copy link
Contributor

neild commented Jun 4, 2015

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
@josharian
Copy link
Contributor

git bisect indicates CL 5952 (77ccb16). go test -gcflags=-l passes at tip, which seems to confirm that.

@josharian josharian added this to the Go1.5 milestone Jun 4, 2015
@josharian josharian changed the title gc: memory corruption (1.5) cmd/compile: bad inlining Jun 4, 2015
@josharian
Copy link
Contributor

Looks like a bad interaction between transitive inlining across packages and escape analysis. @dr2chase want this one?

@josharian josharian changed the title cmd/compile: bad inlining cmd/compile: incorrect escape analysis after transitive inlining across packages Jun 4, 2015
@gopherbot
Copy link

CL https://golang.org/cl/11088 mentions this issue.

josharian added a commit to josharian/go that referenced this issue May 30, 2016
Relevant issues: golang#5056, golang#9537, and golang#11053.
Their tests all pass.

Change-Id: Ibbe05982ed5f332149ffd2cb6a232b8d677c4454
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@gopherbot
Copy link

CL https://golang.org/cl/27464 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants