]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: don't evaluate side effects of range over array
authorKeith Randall <khr@golang.org>
Wed, 19 Mar 2025 17:17:22 +0000 (10:17 -0700)
committerKeith Randall <khr@golang.org>
Mon, 21 Apr 2025 22:50:43 +0000 (15:50 -0700)
commit8af32240c6c8f21695cdcb3b6df8293d7f2d3bc7
treee57483e9747e59aa32d85c66ef34726c9566e8bb
parent04a9b16f3d69aa66f3aaab44dcd322e4a02a82aa
cmd/compile: don't evaluate side effects of range over array

If the thing we're ranging over is an array or ptr to array, and
it doesn't have a function call or channel receive in it, then we
shouldn't evaluate it.

Typecheck the ranged-over value as a constant in that case.
That makes the unified exporter replace the range expression
with a constant int.

Change-Id: I0d4ea081de70d20cf6d1fa8d25ef6cb021975554
Reviewed-on: https://go-review.googlesource.com/c/go/+/659317
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/ssa/nilcheck.go
src/cmd/compile/internal/types2/range.go
src/cmd/compile/internal/walk/range.go
src/go/types/range.go
test/codegen/issue52635.go