cmd/compile: use new for loop semantics for Go 1.22+ compilations

This includes version-dependent support for GOEXPERIMENT and
-d=loopvar, -d=loopvarhash, to allow testing/porting of old code.

Includes tests of downgrade (1.22 -> 1.21) and upgrade (1.21 -> 1.22)
based on //go:build lines (while running a 1.22 build/compiler).

Change-Id: Idd3be61a2b46acec33c7e7edac0924158cc726b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/508819
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
David Chase 2023-07-05 16:21:19 -04:00
parent 6d8d88a707
commit fe1daf2e43
7 changed files with 239 additions and 12 deletions

View file

@ -1897,10 +1897,10 @@ func (r *reader) forStmt(label *types.Sym) ir.Node {
cond := r.optExpr()
post := r.stmt()
body := r.blockStmt()
dv := r.Bool()
perLoopVars := r.Bool()
r.closeAnotherScope()
stmt := ir.NewForStmt(pos, init, cond, post, body, dv)
stmt := ir.NewForStmt(pos, init, cond, post, body, perLoopVars)
stmt.Label = label
return stmt
}