Commit 6c14059e authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

[dev.ssa] cmd/compile/ssa: handle loops that don't loop

Loops such as

func f(c chan int) int {
	for x := range c {
		return x
	}
	return 0
}

don't loop. Remove the assumption that they must.

Partly fixes the build.

Change-Id: I766cebeec8e36d14512bea26f54c06c8eaf95e23
Reviewed-on: https://go-review.googlesource.com/11876Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent d465f049
...@@ -409,8 +409,11 @@ func (s *state) stmt(n *Node) { ...@@ -409,8 +409,11 @@ func (s *state) stmt(n *Node) {
s.stmt(n.Right) s.stmt(n.Right)
} }
b = s.endBlock() b = s.endBlock()
addEdge(b, bCond) // If the body ends in a return statement,
// the condition check and loop are unreachable.
if b != nil {
addEdge(b, bCond)
}
s.startBlock(bEnd) s.startBlock(bEnd)
case OCALLFUNC: case OCALLFUNC:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment