File tree 2 files changed +18
-1
lines changed
src/cmd/compile/internal/walk 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,11 @@ func walkClear(n *ir.UnaryExpr) ir.Node {
135
135
typ := n .X .Type ()
136
136
switch {
137
137
case typ .IsSlice ():
138
- return arrayClear (n .X .Pos (), n .X , nil )
138
+ if n := arrayClear (n .X .Pos (), n .X , nil ); n != nil {
139
+ return n
140
+ }
141
+ // If n == nil, we are clearing an array which takes zero memory, do nothing.
142
+ return ir .NewBlockStmt (n .Pos (), nil )
139
143
case typ .IsMap ():
140
144
return mapClear (n .X , reflectdata .TypePtrAt (n .X .Pos (), n .X .Type ()))
141
145
}
Original file line number Diff line number Diff line change
1
+ // compile
2
+
3
+ // Copyright 2023 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package main
8
+
9
+ var V = []struct {}{}
10
+
11
+ func main () {
12
+ clear (V )
13
+ }
You can’t perform that action at this time.
0 commit comments