From: Josh Bleecher Snyder Date: Sat, 4 Jul 2015 16:07:54 +0000 (-0700) Subject: [dev.ssa] cmd/compile/ssa: handle loops that don't loop X-Git-Tag: go1.7beta1~1623^2^2~409 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6c14059e65b180e3aaf34774b67ddffa461cf3c2;p=gostls13.git [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/11876 Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index b21b4137dc..14c39d337f 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -409,8 +409,11 @@ func (s *state) stmt(n *Node) { s.stmt(n.Right) } 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) case OCALLFUNC: