aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2026-02-10 17:44:08 -0800
committerDavid Chase <drchase@google.com>2026-02-26 11:45:11 -0800
commitef041913a827cbd63a23c5029b87991c6e49529e (patch)
tree9c9a6ae9a8f05abe54917d2bd619747e2c144764
parent155c25e249cab56f740aa93c81ebcb761dd32290 (diff)
downloadgo-ef041913a827cbd63a23c5029b87991c6e49529e.tar.xz
[release-branch.go1.26] cmd/compile: ensure StructMake/ArrayMake1 of direct interfaces are unwrapped
Ensures that deeply nested structs that have the underlying shape of a pointer get unwrapped properly. Update #77536 Change-Id: I004f424d2c62ec7026281daded9b3d96c021e2e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/747760 Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> (cherry picked from commit 1aa534dbb8970b86b0f4059b7665e3505d145e25) Reviewed-on: https://go-review.googlesource.com/c/go/+/749460
-rw-r--r--src/cmd/compile/internal/ssa/_gen/dec.rules4
-rw-r--r--src/cmd/compile/internal/ssa/rewritedec.go4
-rw-r--r--test/fixedbugs/issue77534.go19
3 files changed, 26 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/dec.rules b/src/cmd/compile/internal/ssa/_gen/dec.rules
index fce0026211..a04a7cd5f8 100644
--- a/src/cmd/compile/internal/ssa/_gen/dec.rules
+++ b/src/cmd/compile/internal/ssa/_gen/dec.rules
@@ -80,7 +80,9 @@
// interface ops
(ITab (IMake itab _)) => itab
-(IData (IMake _ data)) => data
+(IData (IMake _ data)) && data.Op != OpStructMake && data.Op != OpArrayMake1 => data
+// Note: the conditional on data.Op ensures that StructMake/ArrayMake1 ops are
+// unwrapped before the IMake is thrown away. See issue 77534.
(Load <t> ptr mem) && t.IsInterface() =>
(IMake
diff --git a/src/cmd/compile/internal/ssa/rewritedec.go b/src/cmd/compile/internal/ssa/rewritedec.go
index c45034ead0..1e5c19cd23 100644
--- a/src/cmd/compile/internal/ssa/rewritedec.go
+++ b/src/cmd/compile/internal/ssa/rewritedec.go
@@ -242,12 +242,16 @@ func rewriteValuedec_OpIData(v *Value) bool {
config := b.Func.Config
typ := &b.Func.Config.Types
// match: (IData (IMake _ data))
+ // cond: data.Op != OpStructMake && data.Op != OpArrayMake1
// result: data
for {
if v_0.Op != OpIMake {
break
}
data := v_0.Args[1]
+ if !(data.Op != OpStructMake && data.Op != OpArrayMake1) {
+ break
+ }
v.copyOf(data)
return true
}
diff --git a/test/fixedbugs/issue77534.go b/test/fixedbugs/issue77534.go
index ab4f922308..77a6e616e6 100644
--- a/test/fixedbugs/issue77534.go
+++ b/test/fixedbugs/issue77534.go
@@ -34,3 +34,22 @@ func f3(p, x, y *T, b bool) {
func f4(i any) T {
return i.(T)
}
+
+type Inner struct {
+ a struct{}
+ p *byte
+}
+
+type Outer struct {
+ inner Inner
+}
+
+func f5(o1, o2 Outer, c bool) Outer {
+ var i any
+ if c {
+ i = o1
+ } else {
+ i = o2
+ }
+ return i.(Outer)
+}