aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2020-10-02 14:53:48 -0400
committerDavid Chase <drchase@google.com>2020-10-06 15:37:42 +0000
commitf8d80977b784fd4879963e61dc9fca1fc9bf2193 (patch)
tree27a7b8f1fef2f0cd1c61cc20ab83a14eb0811003 /test
parentd2a80f3fb5b44450e0b304ac5a718f99c053d82a (diff)
downloadgo-f8d80977b784fd4879963e61dc9fca1fc9bf2193.tar.gz
go-f8d80977b784fd4879963e61dc9fca1fc9bf2193.zip
cmd/compile: correct leaf type when "selecting" singleton register-sized struct
Two part fix: 1) bring the type "correction" forward from a later CL in the expand calls series 2) when a leaf-selwect is rewritten in place, update the type (it might have been changed by the type correction in 1). Fixes #41736. Change-Id: Id097efd10481bf0ad92aaead81a7207221c144b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/259203 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue41736.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/test/fixedbugs/issue41736.go b/test/fixedbugs/issue41736.go
new file mode 100644
index 0000000000..36f127f4fb
--- /dev/null
+++ b/test/fixedbugs/issue41736.go
@@ -0,0 +1,105 @@
+// compile
+
+// Copyright 2020 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 p
+
+type I struct {
+ x int64
+}
+
+type F struct {
+ x float64
+}
+
+type C struct {
+ x *complex128
+}
+
+type D struct {
+ x complex64
+}
+
+type A [1]*complex128
+
+//go:noinline
+func (i I) X() C {
+ cx := complex(0, float64(i.x))
+ return C{&cx}
+}
+
+//go:noinline
+func (f F) X() C {
+ cx := complex(f.x, 0)
+ return C{&cx}
+}
+
+//go:noinline
+func (c C) X() C {
+ cx := complex(imag(*c.x), real(*c.x))
+ return C{&cx}
+}
+
+//go:noinline
+func (d D) X() C {
+ cx := complex(float64(imag(d.x)), -float64(real(d.x)))
+ return C{&cx}
+}
+
+//go:noinline
+func (a A) X() C {
+ cx := complex(-float64(imag(*a[0])), float64(real(*a[0])))
+ return C{&cx}
+}
+
+//go:noinline
+func (i I) id() I {
+ return i
+}
+
+//go:noinline
+func (f F) id() F {
+ return f
+}
+
+//go:noinline
+func (c C) id() C {
+ return c
+}
+
+//go:noinline
+func (d D) id() D {
+ return d
+}
+
+//go:noinline
+func (a A) id() A {
+ return a
+}
+
+type T interface {
+ X() C
+}
+
+func G(x []T) []T {
+ var y []T
+ for _, a := range x {
+ var v T
+ switch u := a.(type) {
+ case I:
+ v = u.id()
+ case F:
+ v = u.id()
+ case C:
+ v = u.id()
+ case D:
+ v = u.id()
+ case A:
+ v = u.id()
+ }
+ y = append(y, v)
+ }
+ return y
+}