Skip to content

Commit bcd25c7

Browse files
committed
cmd/compile: allow StructSelect [x] of interface data fields for x>0
As of CL 681937 we can now have structs which are pointer shaped, but their pointer field is not the first field, like struct{ struct{}; *int }. Fixes #74888 Change-Id: Idc80f6b1abde3ae01437e2a9cadb5aa23d04b806 Reviewed-on: https://go-review.googlesource.com/c/go/+/693415 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b0945a5 commit bcd25c7

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/cmd/compile/internal/ssa/_gen/dec.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
// Some of these are copied from generic.rules
9999

100100
(IMake _typ (StructMake val)) => (IMake _typ val)
101-
(StructSelect [0] (IData x)) => (IData x)
101+
(StructSelect (IData x)) => (IData x)
102102

103103
(StructSelect [i] x:(StructMake ___)) => x.Args[i]
104104

@@ -109,7 +109,7 @@
109109
// More annoying case: (ArraySelect[0] (StructSelect[0] isAPtr))
110110
// There, result of the StructSelect is an Array (not a pointer) and
111111
// the pre-rewrite input to the ArraySelect is a struct, not a pointer.
112-
(StructSelect [0] x) && x.Type.IsPtrShaped() => x
112+
(StructSelect x) && x.Type.IsPtrShaped() => x
113113
(ArraySelect [0] x) && x.Type.IsPtrShaped() => x
114114

115115
// These, too. Bits is bits.

src/cmd/compile/internal/ssa/rewritedec.go

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue74888.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile
2+
3+
// Copyright 2025 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+
type P struct {
10+
q struct{}
11+
p *int
12+
}
13+
14+
func f(x any) {
15+
h(x.(P))
16+
}
17+
18+
//go:noinline
19+
func h(P) {
20+
}

0 commit comments

Comments
 (0)