From 8af32240c6c8f21695cdcb3b6df8293d7f2d3bc7 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 19 Mar 2025 10:17:22 -0700 Subject: 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Griesemer --- test/codegen/issue52635.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/issue52635.go b/test/codegen/issue52635.go index 9b08cade36..9ee63f0fbe 100644 --- a/test/codegen/issue52635.go +++ b/test/codegen/issue52635.go @@ -12,6 +12,7 @@ package codegen type T struct { a *[10]int b [10]int + s []int } func (t *T) f() { @@ -38,4 +39,15 @@ func (t *T) f() { for i := range *t.a { (*t.a)[i] = 0 } + + // amd64:-".*runtime.memclrNoHeapPointers" + // amd64:"DUFFZERO" + for i := range t.b { + t.b[i] = 0 + } + + // amd64:".*runtime.memclrNoHeapPointers" + for i := range t.s { + t.s[i] = 0 + } } -- cgit v1.3