]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile/ssa: handle loops that don't loop
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 4 Jul 2015 16:07:54 +0000 (09:07 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 5 Jul 2015 03:52:34 +0000 (03:52 +0000)
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 <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go

index b21b4137dcd8f3047a5b8277257016ee08042e22..14c39d337f20b254d76592a97645397aa6347f2f 100644 (file)
@@ -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: