Skip to content

Commit be15292

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: fix ICE when compiling global a, b = f()
CL 327651 rewrites a, b = f() to use temporaries when types are not identical. That would leave OAS2 node appears in body of init function for global variables initialization. The staticinit pass is not updated to handle OAS2 node, causing ICE when compiling global variables. To fix this, handle OAS2 nodes like other OAS2*, since they mostly necessitate dynamic execution anyway. Fixes #68264 Change-Id: I1eff8cc3e47035738a2c70d3169e35ec36ee9242 Reviewed-on: https://go-review.googlesource.com/c/go/+/596055 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]>
1 parent 82c1434 commit be15292

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/cmd/compile/internal/staticinit/sched.go

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ func (s *Schedule) tryStaticInit(n ir.Node) bool {
107107
case ir.OAS:
108108
n := n.(*ir.AssignStmt)
109109
lhs, rhs = []ir.Node{n.X}, n.Y
110+
case ir.OAS2:
111+
// Usually OAS2 has been rewritten to separate OASes by types2.
112+
// What's left here is "var a, b = tmp1, tmp2" as a result from rewriting
113+
// "var a, b = f()" that needs type conversion, which is not static.
114+
n := n.(*ir.AssignListStmt)
115+
for _, rhs := range n.Rhs {
116+
for rhs.Op() == ir.OCONVNOP {
117+
rhs = rhs.(*ir.ConvExpr).X
118+
}
119+
if name, ok := rhs.(*ir.Name); !ok || !name.AutoTemp() {
120+
base.FatalfAt(n.Pos(), "unexpected rhs, not an autotmp: %+v", rhs)
121+
}
122+
}
123+
return false
110124
case ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV:
111125
n := n.(*ir.AssignListStmt)
112126
if len(n.Lhs) < 2 || len(n.Rhs) != 1 {

test/fixedbugs/issue68264.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile
2+
3+
// Copyright 2024 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 p
8+
9+
type nat []int
10+
11+
var a, b nat = y()
12+
13+
func y() (nat, []int) {
14+
return nat{0}, nat{1}
15+
}

0 commit comments

Comments
 (0)