]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: allow more args in StructMake folding rule
authorKeith Randall <khr@golang.org>
Wed, 6 Aug 2025 16:21:41 +0000 (09:21 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 6 Aug 2025 18:04:07 +0000 (11:04 -0700)
imakeOfStructMake does the right thing, but we never call it
when the StructMake has more than one argument.

Fixes #74908

Change-Id: Ib4b1a025bfb1fa69a325207e47b74bd6217092bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/693615
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
test/fixedbugs/issue74908.go [new file with mode: 0644]

index 8f354e977f9af2968c64e0b7cc9a1d71c2b8f1d8..793f0a4fb6f0341a41385c9035cc5bdd2d729d2e 100644 (file)
   @x.Block (Load <v.Type> (OffPtr <v.Type.PtrTo()> [t.FieldOff(int(i))] ptr) mem)
 
 // Putting struct{*byte} and similar into direct interfaces.
-(IMake _typ (StructMake val)) => imakeOfStructMake(v)
+(IMake _typ (StructMake ___)) => imakeOfStructMake(v)
 (StructSelect [_] (IData x)) => (IData x)
 
 // un-SSAable values use mem->mem copies
index 83be129a7bc49b66ca025d3ce95a95a9d4706e34..adc4984b6f0c34f8463d4e0ca41551f97e30665e 100644 (file)
@@ -11200,10 +11200,10 @@ func rewriteValuegeneric_OpFloor(v *Value) bool {
 func rewriteValuegeneric_OpIMake(v *Value) bool {
        v_1 := v.Args[1]
        v_0 := v.Args[0]
-       // match: (IMake _typ (StructMake val))
+       // match: (IMake _typ (StructMake ___))
        // result: imakeOfStructMake(v)
        for {
-               if v_1.Op != OpStructMake || len(v_1.Args) != 1 {
+               if v_1.Op != OpStructMake {
                        break
                }
                v.copyOf(imakeOfStructMake(v))
diff --git a/test/fixedbugs/issue74908.go b/test/fixedbugs/issue74908.go
new file mode 100644 (file)
index 0000000..66e26d3
--- /dev/null
@@ -0,0 +1,25 @@
+// compile
+
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+type Type struct {
+       any
+}
+
+type typeObject struct {
+       e struct{}
+       b *byte
+}
+
+func f(b *byte) Type {
+       return Type{
+               typeObject{
+                       b: b,
+               },
+       }
+
+}