test: add new Go tests from source repo
authorIan Lance Taylor <iant@golang.org>
Wed, 16 Dec 2020 22:52:57 +0000 (14:52 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 16 Dec 2020 22:53:31 +0000 (14:53 -0800)
14 files changed:
gcc/testsuite/go.test/test/fixedbugs/bug13343.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug19403.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug369.dir/main.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug483.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug484.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug485.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug486.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug490.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug491.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug495.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug498.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug510.dir/a.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug510.dir/b.go [new file with mode: 0644]
gcc/testsuite/go.test/test/fixedbugs/bug510.go [new file with mode: 0644]

diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug13343.go b/gcc/testsuite/go.test/test/fixedbugs/bug13343.go
new file mode 100644 (file)
index 0000000..a7febea
--- /dev/null
@@ -0,0 +1,18 @@
+// errorcheck
+
+// Copyright 2015 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
+
+var (
+       a, b = f() // ERROR "initialization loop|depends upon itself|depend upon each other"
+       c    = b   // GCCGO_ERROR "depends upon itself|depend upon each other"
+)
+
+func f() (int, int) {
+       return c, c
+}
+
+func main() {}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug19403.go b/gcc/testsuite/go.test/test/fixedbugs/bug19403.go
new file mode 100644 (file)
index 0000000..94c0fb4
--- /dev/null
@@ -0,0 +1,134 @@
+// run
+
+// Copyright 2017 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.
+
+// Test for golang.org/issue/19403.
+// F15 should not be clobbered by float-to-int conversion on ARM.
+// This test requires enough locals that can be put in registers that the compiler can choose to use F15.
+package main
+
+var count float32 = 16
+var i0 int
+var i1 int
+var i2 int
+var i3 int
+var i4 int
+var i5 int
+var i6 int
+var i7 int
+var i8 int
+var i9 int
+var i10 int
+var i11 int
+var i12 int
+var i13 int
+var i14 int
+var i15 int
+var i16 int
+
+func main() {
+       var f0 float32 = 0.0
+       var f1 float32 = 1.0
+       var f2 float32 = 2.0
+       var f3 float32 = 3.0
+       var f4 float32 = 4.0
+       var f5 float32 = 5.0
+       var f6 float32 = 6.0
+       var f7 float32 = 7.0
+       var f8 float32 = 8.0
+       var f9 float32 = 9.0
+       var f10 float32 = 10.0
+       var f11 float32 = 11.0
+       var f12 float32 = 12.0
+       var f13 float32 = 13.0
+       var f14 float32 = 14.0
+       var f15 float32 = 15.0
+       var f16 float32 = 16.0
+       i0 = int(f0)
+       i1 = int(f1)
+       i2 = int(f2)
+       i3 = int(f3)
+       i4 = int(f4)
+       i5 = int(f5)
+       i6 = int(f6)
+       i7 = int(f7)
+       i8 = int(f8)
+       i9 = int(f9)
+       i10 = int(f10)
+       i11 = int(f11)
+       i12 = int(f12)
+       i13 = int(f13)
+       i14 = int(f14)
+       i15 = int(f15)
+       i16 = int(f16)
+       if f16 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f15 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f14 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f13 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f12 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f11 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f10 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f9 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f8 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f7 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f6 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f5 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f4 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f3 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f2 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f1 != count {
+               panic("fail")
+       }
+       count -= 1
+       if f0 != count {
+               panic("fail")
+       }
+       count -= 1
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug369.dir/main.go b/gcc/testsuite/go.test/test/fixedbugs/bug369.dir/main.go
new file mode 100644 (file)
index 0000000..03b53a5
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright 2011 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 (
+       "flag"
+       "os"
+       "runtime"
+       "testing"
+
+       fast "./fast"
+       slow "./slow"
+)
+
+var buf = make([]byte, 1048576)
+
+func BenchmarkFastNonASCII(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               fast.NonASCII(buf, 0)
+       }
+}
+
+func BenchmarkSlowNonASCII(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               slow.NonASCII(buf, 0)
+       }
+}
+
+func main() {
+       testing.Init()
+       os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
+       flag.Parse()
+
+       rslow := testing.Benchmark(BenchmarkSlowNonASCII)
+       rfast := testing.Benchmark(BenchmarkFastNonASCII)
+       tslow := rslow.NsPerOp()
+       tfast := rfast.NsPerOp()
+
+       // Optimization should be good for at least 2x, but be forgiving.
+       // On the ARM simulator we see closer to 1.5x.
+       speedup := float64(tslow) / float64(tfast)
+       want := 1.8
+       if runtime.GOARCH == "arm" {
+               want = 1.3
+       }
+       if speedup < want {
+               // TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on
+               // a Lenovo x200 (linux-amd64) laptop.
+               // println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want)
+               // println("not fast enough")
+               // os.Exit(1)
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug483.go b/gcc/testsuite/go.test/test/fixedbugs/bug483.go
new file mode 100644 (file)
index 0000000..8db6425
--- /dev/null
@@ -0,0 +1,36 @@
+// run
+
+// Copyright 2014 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.
+
+// Test for a garbage collection bug involving not
+// marking x as having its address taken by &x[0]
+// when x is an array value.
+
+package main
+
+import (
+       "bytes"
+       "fmt"
+       "runtime"
+)
+
+func main() {
+       var x = [4]struct{ x, y interface{} }{
+               {"a", "b"},
+               {"c", "d"},
+               {"e", "f"},
+               {"g", "h"},
+       }
+
+       var buf bytes.Buffer
+       for _, z := range x {
+               runtime.GC()
+               fmt.Fprintf(&buf, "%s %s ", z.x.(string), z.y.(string))
+       }
+
+       if buf.String() != "a b c d e f g h " {
+               println("BUG wrong output\n", buf.String())
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug484.go b/gcc/testsuite/go.test/test/fixedbugs/bug484.go
new file mode 100644 (file)
index 0000000..bd4fa51
--- /dev/null
@@ -0,0 +1,78 @@
+// run
+
+// Copyright 2014 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.
+
+// The liveness code used to say that, in func g, s was live
+// starting at its declaration, because it appears to have its
+// address taken by the closure (different s, but the parser
+// gets slightly confused, a separate bug). The liveness analysis
+// saw s as having its address taken but the register optimizer
+// did not. This mismatch meant that s would be marked live
+// (and therefore initialized) at the call to f, but the register optimizer
+// would optimize away the initialization of s before f, causing the
+// garbage collector to use unused data.
+// The register optimizer has been changed to respect the
+// same "address taken" flag that the liveness analysis uses,
+// even if it cannot see any address being taken in the actual
+// machine code. This is conservative but keeps the two consistent,
+// which is the most important thing.
+
+package main
+
+import "runtime"
+
+//go:noinline
+func f() interface{} {
+       runtime.GC()
+       return nil
+}
+
+//go:noinline
+func g() {
+       var s interface{}
+       _ = func() {
+               s := f()
+               _ = s
+       }
+       s = f()
+       useiface(s)
+       useiface(s)
+}
+
+//go:noinline
+func useiface(x interface{}) {
+}
+
+//go:noinline
+func h() {
+       var x [16]uintptr
+       for i := range x {
+               x[i] = 1
+       }
+
+       useint(x[0])
+       useint(x[1])
+       useint(x[2])
+       useint(x[3])
+}
+
+//go:noinline
+func useint(x uintptr) {
+}
+
+func main() {
+       // scribble non-zero values on stack
+       h()
+       // call function that used to let the garbage collector
+       // see uninitialized stack values; it will see the
+       // nonzero values.
+       g()
+}
+
+func big(x int) {
+       if x >= 0 {
+               big(x - 1)
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug485.go b/gcc/testsuite/go.test/test/fixedbugs/bug485.go
new file mode 100644 (file)
index 0000000..c99faed
--- /dev/null
@@ -0,0 +1,39 @@
+// run
+
+// Copyright 2014 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.
+
+// Gccgo chose the wrong embedded method when the same type appeared
+// at different levels and the correct choice was not the first
+// appearance of the type in a depth-first search.
+
+package main
+
+type embedded string
+
+func (s embedded) val() string {
+       return string(s)
+}
+
+type A struct {
+       embedded
+}
+
+type B struct {
+       A
+       embedded
+}
+
+func main() {
+       b := &B{
+               A: A{
+                       embedded: "a",
+               },
+               embedded: "b",
+       }
+       s := b.val()
+       if s != "b" {
+               panic(s)
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug486.go b/gcc/testsuite/go.test/test/fixedbugs/bug486.go
new file mode 100644 (file)
index 0000000..9ad23b3
--- /dev/null
@@ -0,0 +1,14 @@
+// compile
+
+// Copyright 2014 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.
+
+// The gccgo lexer had a bug handling nested comments.
+// http://gcc.gnu.org/PR61746
+// http://code.google.com/p/gofrontend/issues/detail?id=35
+
+package main
+
+/*// comment
+*/
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug490.go b/gcc/testsuite/go.test/test/fixedbugs/bug490.go
new file mode 100644 (file)
index 0000000..387a680
--- /dev/null
@@ -0,0 +1,16 @@
+// compile
+
+// Copyright 2014 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.
+
+// The gccgo compiler used to crash building a comparison between an
+// interface and an empty struct literal.
+
+package p
+type S struct{}
+
+func F(v interface{}) bool {
+       return v == S{}
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug491.go b/gcc/testsuite/go.test/test/fixedbugs/bug491.go
new file mode 100644 (file)
index 0000000..39a3509
--- /dev/null
@@ -0,0 +1,110 @@
+// run
+
+// Copyright 2014 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.
+
+// Test order of calls to builtin functions.
+// Discovered during CL 144530045 review.
+
+package main
+
+func main() {
+       // append
+       {
+               x := make([]int, 0)
+               f := func() int { x = make([]int, 2); return 2 }
+               a, b, c := append(x, 1), f(), append(x, 1)
+               if len(a) != 1 || len(c) != 3 {
+                       bug()
+                       println("append call not ordered:", len(a), b, len(c))
+               }
+       }
+
+       // cap
+       {
+               x := make([]int, 1)
+               f := func() int { x = make([]int, 3); return 2 }
+               a, b, c := cap(x), f(), cap(x)
+               if a != 1 || c != 3 {
+                       bug()
+                       println("cap call not ordered:", a, b, c)
+               }
+       }
+
+       // complex
+       {
+               x := 1.0
+               f := func() int { x = 3; return 2 }
+               a, b, c := complex(x, 0), f(), complex(x, 0)
+               if real(a) != 1 || real(c) != 3 {
+                       bug()
+                       println("complex call not ordered:", a, b, c)
+               }
+       }
+
+       // copy
+       {
+               tmp := make([]int, 100)
+               x := make([]int, 1)
+               f := func() int { x = make([]int, 3); return 2 }
+               a, b, c := copy(tmp, x), f(), copy(tmp, x)
+               if a != 1 || c != 3 {
+                       bug()
+                       println("copy call not ordered:", a, b, c)
+               }
+       }
+
+       // imag
+       {
+               x := 1i
+               f := func() int { x = 3i; return 2 }
+               a, b, c := imag(x), f(), imag(x)
+               if a != 1 || c != 3 {
+                       bug()
+                       println("imag call not ordered:", a, b, c)
+               }
+       }
+
+       // len
+       {
+               x := make([]int, 1)
+               f := func() int { x = make([]int, 3); return 2 }
+               a, b, c := len(x), f(), len(x)
+               if a != 1 || c != 3 {
+                       bug()
+                       println("len call not ordered:", a, b, c)
+               }
+       }
+
+       // make
+       {
+               x := 1
+               f := func() int { x = 3; return 2 }
+               a, b, c := make([]int, x), f(), make([]int, x)
+               if len(a) != 1 || len(c) != 3 {
+                       bug()
+                       println("make call not ordered:", len(a), b, len(c))
+               }
+       }
+
+       // real
+       {
+               x := 1 + 0i
+               f := func() int { x = 3; return 2 }
+               a, b, c := real(x), f(), real(x)
+               if a != 1 || c != 3 {
+                       bug()
+                       println("real call not ordered:", a, b, c)
+               }
+       }
+}
+
+var bugged = false
+
+func bug() {
+       if !bugged {
+               println("BUG")
+               bugged = true
+       }
+}
\ No newline at end of file
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug495.go b/gcc/testsuite/go.test/test/fixedbugs/bug495.go
new file mode 100644 (file)
index 0000000..dfc0c9f
--- /dev/null
@@ -0,0 +1,20 @@
+// compile
+
+// Copyright 2015 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.
+
+// Gccgo used to give an incorrect error
+// bug495.go:16:2: error: missing statement after label
+
+package p
+
+func F(i int) {
+       switch i {
+       case 0:
+               goto lab
+       lab:
+               fallthrough
+       case 1:
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug498.go b/gcc/testsuite/go.test/test/fixedbugs/bug498.go
new file mode 100644 (file)
index 0000000..91b5c2f
--- /dev/null
@@ -0,0 +1,23 @@
+// run
+
+// Copyright 2016 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.
+
+// Gccgo incorrectly rejected an assignment to multiple instances of
+// the same variable.
+
+package main
+
+var a int
+
+func F() {
+       a, a, a = 1, 2, 3
+}
+
+func main() {
+       F()
+       if a != 3 {
+               panic(a)
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug510.dir/a.go b/gcc/testsuite/go.test/test/fixedbugs/bug510.dir/a.go
new file mode 100644 (file)
index 0000000..db1cfef
--- /dev/null
@@ -0,0 +1,13 @@
+// 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 a
+
+import "reflect"
+
+type A = map[int] bool
+
+func F() interface{} {
+       return reflect.New(reflect.TypeOf((*A)(nil))).Elem().Interface()
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug510.dir/b.go b/gcc/testsuite/go.test/test/fixedbugs/bug510.dir/b.go
new file mode 100644 (file)
index 0000000..56b0201
--- /dev/null
@@ -0,0 +1,14 @@
+// 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 main
+
+import "./a"
+
+func main() {
+       _, ok := a.F().(*map[int]bool)
+       if !ok {
+               panic("bad type")
+       }
+}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug510.go b/gcc/testsuite/go.test/test/fixedbugs/bug510.go
new file mode 100644 (file)
index 0000000..8a6da5d
--- /dev/null
@@ -0,0 +1,9 @@
+// rundir
+
+// 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.
+
+// Gccgo confused type descriptors for aliases.
+
+package ignored