mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: fix clear on slice with zero size elem
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>
This commit is contained in:
parent
c4db811e44
commit
0b65b02ba5
@ -135,7 +135,11 @@ func walkClear(n *ir.UnaryExpr) ir.Node {
|
||||
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()))
|
||||
}
|
||||
|
13
test/fixedbugs/issue61127.go
Normal file
13
test/fixedbugs/issue61127.go
Normal file
@ -0,0 +1,13 @@
|
||||
// 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user