cmd/gc: implement 'for range x {'

Fixes #6102.

LGTM=gri
R=ken, r, gri
CC=golang-codereviews
https://golang.org/cl/113120043
diff --git a/test/range.go b/test/range.go
index 8effbe9..af89eda 100644
--- a/test/range.go
+++ b/test/range.go
@@ -32,6 +32,13 @@
 		println("Wanted lowercase alphabet; got", s)
 		panic("fail")
 	}
+	n := 0
+	for range seq('a', 'z') {
+		n++
+	}
+	if n != 26 {
+		println("testchan wrong count", n, "want 26")
+	}
 }
 
 // test that range over slice only evaluates
@@ -87,6 +94,22 @@
 	}
 }
 
+func testslice2() {
+	n := 0
+	nmake = 0
+	for range makeslice() {
+		n++
+	}
+	if nmake != 1 {
+		println("range called makeslice", nmake, "times")
+		panic("fail")
+	}
+	if n != 5 {
+		println("wrong count ranging over makeslice", n)
+		panic("fail")
+	}
+}
+
 // test that range over array only evaluates
 // the expression after "range" once.
 
@@ -127,6 +150,22 @@
 	}
 }
 
+func testarray2() {
+	n := 0
+	nmake = 0
+	for range makearray() {
+		n++
+	}
+	if nmake != 1 {
+		println("range called makearray", nmake, "times")
+		panic("fail")
+	}
+	if n != 5 {
+		println("wrong count ranging over makearray", n)
+		panic("fail")
+	}
+}
+
 func makearrayptr() *[5]int {
 	nmake++
 	return &[5]int{1, 2, 3, 4, 5}
@@ -176,6 +215,22 @@
 	}
 }
 
+func testarrayptr2() {
+	n := 0
+	nmake = 0
+	for range makearrayptr() {
+		n++
+	}
+	if nmake != 1 {
+		println("range called makearrayptr", nmake, "times")
+		panic("fail")
+	}
+	if n != 5 {
+		println("wrong count ranging over makearrayptr", n)
+		panic("fail")
+	}
+}
+
 // test that range over string only evaluates
 // the expression after "range" once.
 
@@ -216,6 +271,22 @@
 	}
 }
 
+func teststring2() {
+	n := 0
+	nmake = 0
+	for range makestring() {
+		n++
+	}
+	if nmake != 1 {
+		println("range called makestring", nmake, "times")
+		panic("fail")
+	}
+	if n != 5 {
+		println("wrong count ranging over makestring", n)
+		panic("fail")
+	}
+}
+
 // test that range over map only evaluates
 // the expression after "range" once.
 
@@ -256,6 +327,22 @@
 	}
 }
 
+func testmap2() {
+	n := 0
+	nmake = 0
+	for range makemap() {
+		n++
+	}
+	if nmake != 1 {
+		println("range called makemap", nmake, "times")
+		panic("fail")
+	}
+	if n != 5 {
+		println("wrong count ranging over makemap", n)
+		panic("fail")
+	}
+}
+
 // test that range evaluates the index and value expressions
 // exactly once per iteration.
 
@@ -298,13 +385,18 @@
 	testchan()
 	testarray()
 	testarray1()
+	testarray2()
 	testarrayptr()
 	testarrayptr1()
+	testarrayptr2()
 	testslice()
 	testslice1()
+	testslice2()
 	teststring()
 	teststring1()
+	teststring2()
 	testmap()
 	testmap1()
+	testmap2()
 	testcalls()
 }