From a0dc7bf08481d906cb7d65d86bb347a583d84fd0 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 22 May 2025 18:06:27 +0700 Subject: cmd/compile: fix ICE when transforming loopvar When transforming for loop variables, the compiler does roughly following steps: (1) prebody = {z := z' for z in leaked} ... (4) init' = (init : s/z/z' for z in leaked) However, the definition of z is not updated to `z := z'` statement, causing ReassignOracle incorrectly use the new init statement with z' instead of z, trigger the ICE. Fixing this by updating the correct/new definition statement for z during the prebody initialization. Fixes #73823 Change-Id: Ice2a6741be7478506c58f4000f591d5582029136 Reviewed-on: https://go-review.googlesource.com/c/go/+/675475 Auto-Submit: Cuong Manh Le LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: David Chase --- src/cmd/compile/internal/loopvar/loopvar.go | 1 + 1 file changed, 1 insertion(+) (limited to 'src/cmd/compile') diff --git a/src/cmd/compile/internal/loopvar/loopvar.go b/src/cmd/compile/internal/loopvar/loopvar.go index 030fc04c13..5a4590d299 100644 --- a/src/cmd/compile/internal/loopvar/loopvar.go +++ b/src/cmd/compile/internal/loopvar/loopvar.go @@ -305,6 +305,7 @@ func ForCapture(fn *ir.Func) []VarAndLoop { as := ir.NewAssignStmt(x.Pos(), z, tz) as.Def = true as.SetTypecheck(1) + z.Defn = as preBody.Append(as) dclFixups[z] = as -- cgit v1.3