]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: get rid of zero-sized values in call expansion
authorDavid Chase <drchase@google.com>
Tue, 10 Oct 2023 16:18:43 +0000 (12:18 -0400)
committerDavid Chase <drchase@google.com>
Tue, 10 Oct 2023 16:50:46 +0000 (16:50 +0000)
Do this by removing all stores of zero-sized anything.

Fixes #63433.

Change-Id: I5d8271edab992d15d02005fa3fe31835f2eff8fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/534296
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/ssa/_gen/dec.rules
src/cmd/compile/internal/ssa/rewritedec.go
test/fixedbugs/issue63490.go [new file with mode: 0644]

index 4484cd7e28005040ce024e21daefca914a07956f..2adf061874ccfd45e7f4c314183647836d117faf 100644 (file)
@@ -7,6 +7,8 @@
 // types.  These rules work together with the decomposeBuiltIn
 // pass which handles phis of these types.
 
+(Store {t} _ _ mem) && t.Size() == 0 => mem
+
 // complex ops
 (ComplexReal (ComplexMake real _  )) => real
 (ComplexImag (ComplexMake _ imag )) => imag
index fbfe15c0c58965f9160b1130107199e7f019a007..7468518246dde8d76f353b910a36d49ae8dba2ad 100644 (file)
@@ -583,6 +583,18 @@ func rewriteValuedec_OpStore(v *Value) bool {
        b := v.Block
        config := b.Func.Config
        typ := &b.Func.Config.Types
+       // match: (Store {t} _ _ mem)
+       // cond: t.Size() == 0
+       // result: mem
+       for {
+               t := auxToType(v.Aux)
+               mem := v_2
+               if !(t.Size() == 0) {
+                       break
+               }
+               v.copyOf(mem)
+               return true
+       }
        // match: (Store {t} dst (ComplexMake real imag) mem)
        // cond: t.Size() == 8
        // result: (Store {typ.Float32} (OffPtr <typ.Float32Ptr> [4] dst) imag (Store {typ.Float32} dst real mem))
diff --git a/test/fixedbugs/issue63490.go b/test/fixedbugs/issue63490.go
new file mode 100644 (file)
index 0000000..740ce9b
--- /dev/null
@@ -0,0 +1,36 @@
+// compile
+
+// Copyright 2023 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 ResourceFunc struct {
+       junk [8]int
+       base assignmentBaseResource
+}
+
+type SubscriptionAssignmentResource struct {
+       base assignmentBaseResource
+}
+
+type assignmentBaseResource struct{}
+
+//go:noinline
+func (a assignmentBaseResource) f(s string) ResourceFunc {
+       println(s)
+       return ResourceFunc{}
+}
+
+//go:noinline
+func (r SubscriptionAssignmentResource) Hi() ResourceFunc {
+       rf := r.base.f("Hello world")
+       rf.base = r.base
+       return rf
+}
+
+func main() {
+       var r SubscriptionAssignmentResource
+       r.Hi()
+}