From: Keith Randall Date: Wed, 4 Feb 2026 23:29:40 +0000 (-0800) Subject: cmd/compile: don't double-walk the map argument of clear X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b8bccb97982a7dc340f64d0ad522843418db8810;p=gostls13.git cmd/compile: don't double-walk the map argument of clear mkcallstmt1 already walks the map argument of clear. mapClear then walks it again, which can cause problems if it is some syntax that is non-idempotent under walk. That is the case for the new way map lookups are being lowered in CL 736020. Fixes #77435 Change-Id: Ib2f6d7f2270308c2462aa276ed4413aaf7799fe3 Reviewed-on: https://go-review.googlesource.com/c/go/+/742120 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Cherry Mui --- diff --git a/src/cmd/compile/internal/walk/range.go b/src/cmd/compile/internal/walk/range.go index 866dd23def..e6a9a4bcfb 100644 --- a/src/cmd/compile/internal/walk/range.go +++ b/src/cmd/compile/internal/walk/range.go @@ -477,7 +477,7 @@ func mapClear(m, rtyp ir.Node) ir.Node { // instantiate mapclear(typ *type, hmap map[any]any) fn := typecheck.LookupRuntime("mapclear", t.Key(), t.Elem()) n := mkcallstmt1(fn, rtyp, m) - return walkStmt(typecheck.Stmt(n)) + return typecheck.Stmt(n) } // Lower n into runtime·memclr if possible, for diff --git a/test/fixedbugs/issue77435.go b/test/fixedbugs/issue77435.go new file mode 100644 index 0000000000..f3fc45fc92 --- /dev/null +++ b/test/fixedbugs/issue77435.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 77435: compiler crash on clear of map resulting +// from a map lookup (or some other syntax that is +// non-idempotent during walk). + +package p + +func f(s map[int]map[int]int) { + clear(s[0]) +}