From: Keith Randall Date: Wed, 6 Aug 2025 16:21:41 +0000 (-0700) Subject: cmd/compile: allow more args in StructMake folding rule X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=72e8237cc11569de2faf9885a1b83d06446533b5;p=gostls13.git cmd/compile: allow more args in StructMake folding rule 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 Reviewed-by: David Chase Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules index 8f354e977f..793f0a4fb6 100644 --- a/src/cmd/compile/internal/ssa/_gen/generic.rules +++ b/src/cmd/compile/internal/ssa/_gen/generic.rules @@ -921,7 +921,7 @@ @x.Block (Load (OffPtr [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 diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 83be129a7b..adc4984b6f 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -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 index 0000000000..66e26d32a1 --- /dev/null +++ b/test/fixedbugs/issue74908.go @@ -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, + }, + } + +}