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 evaluation order of select statement clauses #43111

Closed
mdempsky opened this issue Dec 10, 2020 · 2 comments
Closed

cmd/compile: incorrect evaluation order of select statement clauses #43111

mdempsky opened this issue Dec 10, 2020 · 2 comments
Assignees
Labels

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 10, 2020

The program below should run and terminate successfully. It does so when compiled with gccgo, but it fatal errors due to deadlock when compiled with cmd/compile.

package main

var ch = make(chan int)

func f() chan int {
	close(ch)
	ch = nil
	return nil
}

func main() {
	select {
	case <-ch:
	case f() <- 0:
	}
}

The issue is this code responsible for ordering receive clauses within select statements:

r.Right.Left = o.expr(r.Right.Left, nil)
if r.Right.Left.Op != ONAME {
r.Right.Left = o.copyExpr(r.Right.Left, r.Right.Left.Type, false)
}

It should actually be checking IsAutoTmp like the code responsible for ordering send clauses:

r.Left = o.expr(r.Left, nil)
if !r.Left.IsAutoTmp() {
r.Left = o.copyExpr(r.Left, r.Left.Type, false)
}
r.Right = o.expr(r.Right, nil)
if !r.Right.IsAutoTmp() {
r.Right = o.copyExpr(r.Right, r.Right.Type, false)
}

Discovered with @cuonglm.

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Dec 10, 2020

I fixed in https://go-review.googlesource.com/c/go/+/276132/3, not sure this is qualified to fix in go 1.16. Willing to make the fix to master if so.

Loading

@mdempsky mdempsky self-assigned this Dec 10, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 10, 2020

Change https://golang.org/cl/277132 mentions this issue: cmd/compile: fix select statement evaluation order corner case

Loading

@gopherbot gopherbot closed this in 1430552 Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants