aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/codegen/arithmetic.go24
-rw-r--r--test/fixedbugs/gcc101994.go16
-rw-r--r--test/fixedbugs/issue10975.go2
-rw-r--r--test/fixedbugs/issue46938.go29
-rw-r--r--test/fixedbugs/issue47771.go19
-rw-r--r--test/typeparam/issue47878.go46
-rw-r--r--test/typeparam/issue47901.go21
-rw-r--r--test/typeparam/issue47929.go29
-rw-r--r--test/typeparam/issue47948.go18
9 files changed, 203 insertions, 1 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go
index eb0f338036c..eb95416b6aa 100644
--- a/test/codegen/arithmetic.go
+++ b/test/codegen/arithmetic.go
@@ -84,6 +84,30 @@ func NegAddFromConstNeg(a int) int {
return c
}
+func SubSubNegSimplify(a, b int) int {
+ // amd64:"NEGQ"
+ r := (a - b) - a
+ return r
+}
+
+func SubAddSimplify(a, b int) int {
+ // amd64:-"SUBQ",-"ADDQ"
+ r := a + (b - a)
+ return r
+}
+
+func SubAddNegSimplify(a, b int) int {
+ // amd64:"NEGQ",-"ADDQ",-"SUBQ"
+ r := a - (b + a)
+ return r
+}
+
+func AddAddSubSimplify(a, b, c int) int {
+ // amd64:-"SUBQ"
+ r := a + (b + (c - a))
+ return r
+}
+
// -------------------- //
// Multiplication //
// -------------------- //
diff --git a/test/fixedbugs/gcc101994.go b/test/fixedbugs/gcc101994.go
new file mode 100644
index 00000000000..6e1e2b80751
--- /dev/null
+++ b/test/fixedbugs/gcc101994.go
@@ -0,0 +1,16 @@
+// compile
+
+// Copyright 2021 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.
+
+// https://gcc.gnu.org/PR101994
+// gccgo compiler crash with zero-sized result.
+
+package p
+
+type Empty struct{}
+
+func F() (int, Empty) {
+ return 0, Empty{}
+}
diff --git a/test/fixedbugs/issue10975.go b/test/fixedbugs/issue10975.go
index 876ea58ef97..a58ccce2db1 100644
--- a/test/fixedbugs/issue10975.go
+++ b/test/fixedbugs/issue10975.go
@@ -10,7 +10,7 @@
package main
type I interface {
- int // ERROR "interface contains embedded non-interface|not an interface"
+ int // ERROR "interface contains embedded non-interface|embedding non-interface type"
}
func New() I {
diff --git a/test/fixedbugs/issue46938.go b/test/fixedbugs/issue46938.go
new file mode 100644
index 00000000000..87532d47694
--- /dev/null
+++ b/test/fixedbugs/issue46938.go
@@ -0,0 +1,29 @@
+// run -gcflags="-d=checkptr"
+
+// Copyright 2021 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
+
+import (
+ "strings"
+ "unsafe"
+)
+
+func main() {
+ defer func() {
+ err := recover()
+ if err == nil {
+ panic("expected panic")
+ }
+ if got := err.(error).Error(); !strings.Contains(got, "slice bounds out of range") {
+ panic("expected panic slice out of bound, got " + got)
+ }
+ }()
+ s := make([]int64, 100)
+ p := unsafe.Pointer(&s[0])
+ n := 1000
+
+ _ = (*[10]int64)(p)[:n:n]
+}
diff --git a/test/fixedbugs/issue47771.go b/test/fixedbugs/issue47771.go
new file mode 100644
index 00000000000..a434bffe4b1
--- /dev/null
+++ b/test/fixedbugs/issue47771.go
@@ -0,0 +1,19 @@
+// run
+
+// Copyright 2021 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.
+
+// gofrontend miscompiled some cases of append(s, make(typ, ln)...).
+
+package main
+
+var g int
+
+func main() {
+ a := []*int{&g, &g, &g, &g}
+ a = append(a[:0], make([]*int, len(a) - 1)...)
+ if len(a) != 3 || a[0] != nil || a[1] != nil || a[2] != nil {
+ panic(a)
+ }
+}
diff --git a/test/typeparam/issue47878.go b/test/typeparam/issue47878.go
new file mode 100644
index 00000000000..cb1043a4400
--- /dev/null
+++ b/test/typeparam/issue47878.go
@@ -0,0 +1,46 @@
+// compile -G=3
+
+// Copyright 2021 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 Src1[T any] func() Src1[T]
+
+func (s *Src1[T]) Next() {
+ *s = (*s)()
+}
+
+type Src2[T any] []func() Src2[T]
+
+func (s Src2[T]) Next() {
+ _ = s[0]()
+}
+
+type Src3[T comparable] map[T]func() Src3[T]
+
+func (s Src3[T]) Next() {
+ var a T
+ _ = s[a]()
+}
+
+type Src4[T any] chan func() T
+
+func (s Src4[T]) Next() {
+ _ = (<-s)()
+}
+
+func main() {
+ var src1 Src1[int]
+ src1.Next()
+
+ var src2 Src2[int]
+ src2.Next()
+
+ var src3 Src3[string]
+ src3.Next()
+
+ var src4 Src4[int]
+ src4.Next()
+}
diff --git a/test/typeparam/issue47901.go b/test/typeparam/issue47901.go
new file mode 100644
index 00000000000..cd079730115
--- /dev/null
+++ b/test/typeparam/issue47901.go
@@ -0,0 +1,21 @@
+// run -gcflags=-G=3
+
+// Copyright 2021 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 Chan[T any] chan Chan[T]
+
+func (ch Chan[T]) recv() Chan[T] {
+ return <-ch
+}
+
+func main() {
+ ch := Chan[int](make(chan Chan[int]))
+ go func() {
+ ch <- make(Chan[int])
+ }()
+ ch.recv()
+}
diff --git a/test/typeparam/issue47929.go b/test/typeparam/issue47929.go
new file mode 100644
index 00000000000..a5636f2c7ba
--- /dev/null
+++ b/test/typeparam/issue47929.go
@@ -0,0 +1,29 @@
+// compile -G=3 -p=p
+
+// Copyright 2021 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 v4
+
+var sink interface{}
+
+//go:noinline
+func Do(result, body interface{}) {
+ sink = &result
+}
+
+func DataAction(result DataActionResponse, body DataActionRequest) {
+ Do(&result, body)
+}
+
+type DataActionRequest struct {
+ Action *interface{}
+}
+
+type DataActionResponse struct {
+ ValidationErrors *ValidationError
+}
+
+type ValidationError struct {
+}
diff --git a/test/typeparam/issue47948.go b/test/typeparam/issue47948.go
new file mode 100644
index 00000000000..8e5df81f6dc
--- /dev/null
+++ b/test/typeparam/issue47948.go
@@ -0,0 +1,18 @@
+// compile -G=3
+
+// Copyright 2021 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 fun func()
+
+func F[T any]() {
+ _ = fun(func() {
+
+ })
+}
+func main() {
+ F[int]()
+}