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: bad variable misuse in order.go #13469

Closed
mdempsky opened this issue Dec 3, 2015 · 1 comment
Closed

cmd/compile: bad variable misuse in order.go #13469

mdempsky opened this issue Dec 3, 2015 · 1 comment

Comments

@mdempsky
Copy link
Member

mdempsky commented Dec 3, 2015

orderstmt's OSELECT case reuses t as a temporary *NodeList even though it's still live and used for the poptemp call later:

func orderstmt(n *Node, order *Order) {
    ...
    switch n.Op {
    ...
    case OSELECT:
        t := marktemp(order)
        ...
                case OSELRECV, OSELRECV2:
                    if r.Colas {
                        t = r.Ninit
        ...
        poptemp(t, order)
    ...
}

In practice, this currently seems to work out okay because we don't allow inlining of functions with select statements, so marktemp(order) will always return nil, and the r.Colas branch will set t back to nil (or else we'll hit the Yyerror("ninit on select recv") error and fail anyway).

If I comment out OSELECT in inl.go:ishairy, then I notice this program causes marktemp(order) to return non-nil but then t is changed to nil before the poptemp(t, order) call:

package repro

func f() int
func g(int, int) int
func h(ch chan int) int {
    select {
    case x := <-ch:
        return x
    }
}

func repro() {
    g(f(), h(nil))
}
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Dec 14, 2016
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

2 participants