Skip to content

Commit abd55d8

Browse files
committed
cmd/compile: fix inline static init arguments substitued tree
Blank node must be ignored when building arguments substitued tree. Otherwise, it could be used to replace other blank node in left hand side of an assignment, causing an invalid IR node. Consider the following code: type S1 struct { s2 S2 } type S2 struct{} func (S2) Make() S2 { return S2{} } func (S1) Make() S1 { return S1{s2: S2{}.Make()} } var _ = S1{}.Make() After staticAssignInlinedCall, the assignment becomes: var _ = S1{s2: S2{}.Make()} and the arg substitued tree is "map[*ir.Name]ir.Node{_: S1{}}". Now, when doing static assignment, if there is any assignment to blank node, for example: _ := S2{} That blank node will be replaced with "S1{}": S1{} := S2{} So constructing an invalid IR which causes the ICE. Fixes #58325 Change-Id: I21b48357f669a7e02a7eb4325246aadc31f78fb9 Reviewed-on: https://go-review.googlesource.com/c/go/+/465098 Run-TryBot: Cuong Manh Le <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 0b9974d commit abd55d8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ func (s *Schedule) staticAssignInlinedCall(l *ir.Name, loff int64, call *ir.Inli
639639
// Build tree with args substituted for params and try it.
640640
args := make(map[*ir.Name]ir.Node)
641641
for i, v := range as2init.Lhs {
642+
if ir.IsBlank(v) {
643+
continue
644+
}
642645
args[v.(*ir.Name)] = as2init.Rhs[i]
643646
}
644647
r, ok := subst(as2body.Rhs[0], args)

test/fixedbugs/issue58325.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 p
8+
9+
type S1 struct {
10+
s2 S2
11+
}
12+
13+
type S2 struct{}
14+
15+
func (S2) Make() S2 {
16+
return S2{}
17+
}
18+
19+
func (S1) Make() S1 {
20+
return S1{s2: S2{}.Make()}
21+
}
22+
23+
var _ = S1{}.Make()

0 commit comments

Comments
 (0)