Fixed #61127
Change-Id: If07b04ebcc98438c66f273c0c94bea1f230dc2e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/507535
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
typ := n.X.Type()
switch {
case typ.IsSlice():
- return arrayClear(n.X.Pos(), n.X, nil)
+ if n := arrayClear(n.X.Pos(), n.X, nil); n != nil {
+ return n
+ }
+ // If n == nil, we are clearing an array which takes zero memory, do nothing.
+ return ir.NewBlockStmt(n.Pos(), nil)
case typ.IsMap():
return mapClear(n.X, reflectdata.TypePtrAt(n.X.Pos(), n.X.Type()))
}
--- /dev/null
+// compile
+
+// Copyright 2023 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.
+
+package main
+
+var V = []struct{}{}
+
+func main() {
+ clear(V)
+}