diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 4 | ||||
-rw-r--r-- | test/codegen/arithmetic.go | 42 | ||||
-rw-r--r-- | test/codegen/mathbits.go | 14 | ||||
-rw-r--r-- | test/codegen/select.go | 20 | ||||
-rw-r--r-- | test/codegen/slices.go | 21 | ||||
-rw-r--r-- | test/fixedbugs/bug229.go | 8 | ||||
-rw-r--r-- | test/fixedbugs/issue22921.go | 18 | ||||
-rw-r--r-- | test/fixedbugs/issue24491.go | 45 | ||||
-rw-r--r-- | test/fixedbugs/issue38125.go | 22 | ||||
-rw-r--r-- | test/fixedbugs/issue39505.go | 31 | ||||
-rw-r--r-- | test/fixedbugs/issue39505b.go | 183 | ||||
-rw-r--r-- | test/fixedbugs/issue41247.go | 11 | ||||
-rw-r--r-- | test/fixedbugs/issue8606b.go | 63 | ||||
-rw-r--r-- | test/notinheap2.go | 12 | ||||
-rw-r--r-- | test/runtime.go | 2 |
15 files changed, 489 insertions, 7 deletions
diff --git a/test/README.md b/test/README.md index 068dc1b22b..432d36b653 100644 --- a/test/README.md +++ b/test/README.md @@ -6,6 +6,10 @@ To run just these tests, execute: ../bin/go run run.go +To run just tests from specified files in this directory, execute: + + ../bin/go run run.go -- file1.go file2.go ... + Standard library tests should be written as regular Go tests in the appropriate package. The tool chain and runtime also have regular Go tests in their packages. diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index afd4d66bd9..0bdb66a376 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -42,6 +42,48 @@ func SubMem(arr []int, b, c, d int) int { return arr[0] - arr[1] } +func SubFromConst(a int) int { + // ppc64le: `SUBC\tR[0-9]+,\s[$]40,\sR` + // ppc64: `SUBC\tR[0-9]+,\s[$]40,\sR` + b := 40 - a + return b +} + +func SubFromConstNeg(a int) int { + // ppc64le: `ADD\t[$]40,\sR[0-9]+,\sR` + // ppc64: `ADD\t[$]40,\sR[0-9]+,\sR` + c := 40 - (-a) + return c +} + +func SubSubFromConst(a int) int { + // ppc64le: `ADD\t[$]20,\sR[0-9]+,\sR` + // ppc64: `ADD\t[$]20,\sR[0-9]+,\sR` + c := 40 - (20 - a) + return c +} + +func AddSubFromConst(a int) int { + // ppc64le: `SUBC\tR[0-9]+,\s[$]60,\sR` + // ppc64: `SUBC\tR[0-9]+,\s[$]60,\sR` + c := 40 + (20 - a) + return c +} + +func NegSubFromConst(a int) int { + // ppc64le: `ADD\t[$]-20,\sR[0-9]+,\sR` + // ppc64: `ADD\t[$]-20,\sR[0-9]+,\sR` + c := -(20 - a) + return c +} + +func NegAddFromConstNeg(a int) int { + // ppc64le: `SUBC\tR[0-9]+,\s[$]40,\sR` + // ppc64: `SUBC\tR[0-9]+,\s[$]40,\sR` + c := -(-40 + a) + return c +} + // -------------------- // // Multiplication // // -------------------- // diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index 942605de55..4c35f26997 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -76,9 +76,17 @@ func Len64(n uint64) int { // arm:"CLZ" arm64:"CLZ" // mips:"CLZ" // wasm:"I64Clz" + // ppc64le:"SUBC","CNTLZD" + // ppc64:"SUBC","CNTLZD" return bits.Len64(n) } +func SubFromLen64(n uint64) int { + // ppc64le:"CNTLZD",-"SUBC" + // ppc64:"CNTLZD",-"SUBC" + return 64 - bits.Len64(n) +} + func Len32(n uint32) int { // amd64:"BSRQ","LEAQ",-"CMOVQEQ" // s390x:"FLOGR" @@ -291,6 +299,12 @@ func TrailingZeros64(n uint64) int { return bits.TrailingZeros64(n) } +func TrailingZeros64Subtract(n uint64) int { + // ppc64le/power8:"NEG","SUBC","ANDN","POPCNTD" + // ppc64le/power9:"SUBC","CNTTZD" + return bits.TrailingZeros64(1 - n) +} + func TrailingZeros32(n uint32) int { // amd64:"BTSQ\\t\\$32","BSFQ" // arm:"CLZ" diff --git a/test/codegen/select.go b/test/codegen/select.go new file mode 100644 index 0000000000..4426924b36 --- /dev/null +++ b/test/codegen/select.go @@ -0,0 +1,20 @@ +// asmcheck + +// 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 codegen + +func f() { + ch1 := make(chan int) + ch2 := make(chan int) + for { + // amd64:-`MOVQ\t[$]0, ""..autotmp_3` + select { + case <-ch1: + case <-ch2: + default: + } + } +} diff --git a/test/codegen/slices.go b/test/codegen/slices.go index 40e857f9f6..38e8a62f4b 100644 --- a/test/codegen/slices.go +++ b/test/codegen/slices.go @@ -347,3 +347,24 @@ func InitNotSmallSliceLiteral() []int { 42, } } + +// --------------------------------------- // +// Test PPC64 SUBFCconst folding rules // +// triggered by slice operations. // +// --------------------------------------- // + +func SliceWithConstCompare(a []int, b int) []int { + var c []int = []int{1, 2, 3, 4, 5} + if b+len(a) < len(c) { + // ppc64le:-"NEG" + // ppc64:-"NEG" + return c[b:] + } + return a +} + +func SliceWithSubtractBound(a []int, b int) []int { + // ppc64le:"SUBC",-"NEG" + // ppc64:"SUBC",-"NEG" + return a[(3 - b):] +} diff --git a/test/fixedbugs/bug229.go b/test/fixedbugs/bug229.go index 4baf65e48b..a30202fa2c 100644 --- a/test/fixedbugs/bug229.go +++ b/test/fixedbugs/bug229.go @@ -10,11 +10,11 @@ import "testing" func main() { var t testing.T - + // make sure error mentions that // name is unexported, not just "name not found". - t.common.name = nil // ERROR "unexported" - - println(testing.anyLowercaseName("asdf")) // ERROR "unexported" "undefined: testing.anyLowercaseName" + t.common.name = nil // ERROR "unexported" + + println(testing.anyLowercaseName("asdf")) // ERROR "unexported" } diff --git a/test/fixedbugs/issue22921.go b/test/fixedbugs/issue22921.go new file mode 100644 index 0000000000..04f78b2c08 --- /dev/null +++ b/test/fixedbugs/issue22921.go @@ -0,0 +1,18 @@ +// errorcheck + +// 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 "bytes" + +type _ struct{ bytes.nonexist } // ERROR "unexported" + +type _ interface{ bytes.nonexist } // ERROR "unexported" + +func main() { + var _ bytes.Buffer + var _ bytes.buffer // ERROR "unexported" +} diff --git a/test/fixedbugs/issue24491.go b/test/fixedbugs/issue24491.go new file mode 100644 index 0000000000..4703368793 --- /dev/null +++ b/test/fixedbugs/issue24491.go @@ -0,0 +1,45 @@ +// run + +// 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. + +// This test makes sure unsafe-uintptr arguments are handled correctly. + +package main + +import ( + "runtime" + "unsafe" +) + +var done = make(chan bool, 1) + +func setup() unsafe.Pointer { + s := "ok" + runtime.SetFinalizer(&s, func(p *string) { *p = "FAIL" }) + return unsafe.Pointer(&s) +} + +//go:noinline +//go:uintptrescapes +func test(s string, p uintptr) { + runtime.GC() + if *(*string)(unsafe.Pointer(p)) != "ok" { + panic(s + " return unexpected result") + } + done <- true +} + +func main() { + test("normal", uintptr(setup())) + <-done + + go test("go", uintptr(setup())) + <-done + + func() { + defer test("defer", uintptr(setup())) + }() + <-done +} diff --git a/test/fixedbugs/issue38125.go b/test/fixedbugs/issue38125.go new file mode 100644 index 0000000000..1207aecd39 --- /dev/null +++ b/test/fixedbugs/issue38125.go @@ -0,0 +1,22 @@ +// 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. + +// gccgo mishandled embedded methods of type aliases. + +package p + +type I int + +func (I) M() {} + +type T = struct { + I +} + +func F() { + _ = T.M + _ = struct { I }.M +} diff --git a/test/fixedbugs/issue39505.go b/test/fixedbugs/issue39505.go new file mode 100644 index 0000000000..711b562867 --- /dev/null +++ b/test/fixedbugs/issue39505.go @@ -0,0 +1,31 @@ +// 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 + +func f() { + if len([]int{})-1 < len([]int{}) { + } + + var st struct { + i int + } + g := func() string { + return "" + } + h := func(string) string { + return g() + g() + } + s, i := "", 0 + + st.i = len(s) + i = len(h(s[i+0:i+1])) + len(s[len(s)+1:i+1]) + s = s[(len(s[i+1:len(s)+1])+1):len(h(""))+1] + (s[i+1 : len([]int{})+i]) + i = 1 + len([]int{len([]string{s[i+len([]int{}) : len(s)+i]})}) + + var ch chan int + ch <- len(h("")) - len(s) +} diff --git a/test/fixedbugs/issue39505b.go b/test/fixedbugs/issue39505b.go new file mode 100644 index 0000000000..ecf1ab64f4 --- /dev/null +++ b/test/fixedbugs/issue39505b.go @@ -0,0 +1,183 @@ +// run + +// 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 + +func main() { + ff := []func(){lt_f1, lt_f2, lt_f3, lt_f4, lt_f5, lt_f6, lt_f7, lt_f8, lt_f9, + gt_f1, gt_f2, gt_f3, le_f1, le_f2, le_f3, ge_f1, ge_f2, ge_f3} + + for _, f := range ff { + f() + } +} + +func lt_f1() { + const c = 1 + var a = 0 + var v *int = &a + if *v-c < len([]int{}) { + } else { + panic("bad") + } +} + +func lt_f2() { + const c = 10 + var a = 0 + var v *int = &a + if *v+c < len([]int{}) { + panic("bad") + } +} + +func lt_f3() { + const c = -10 + var a = 0 + var v *int = &a + if *v|0xff+c < len([]int{}) { + panic("bad") + } +} + +func lt_f4() { + const c = 10 + var a = 0 + var v *int = &a + if *v|0x0f+c < len([]int{}) { + panic("bad") + } +} + +func lt_f5() { + const c int32 = 1 + var a int32 = 0 + var v *int32 = &a + if *v-c < int32(len([]int32{})) { + } else { + panic("bad") + } +} + +func lt_f6() { + const c int32 = 10 + var a int32 = 0 + var v *int32 = &a + if *v+c < int32(len([]int32{})) { + panic("bad") + } +} + +func lt_f7() { + const c int32 = -10 + var a int32 = 0 + var v *int32 = &a + if *v|0xff+c < int32(len([]int{})) { + panic("bad") + } +} + +func lt_f8() { + const c int32 = 10 + var a int32 = 0 + var v *int32 = &a + if *v|0x0f+c < int32(len([]int{})) { + panic("bad") + } +} + +func lt_f9() { + const c int32 = -10 + var a int32 = 0 + var v *int32 = &a + if *v|0x0a+c < int32(len([]int{})) { + panic("bad") + } +} + +func gt_f1() { + const c = 1 + var a = 0 + var v *int = &a + if len([]int{}) > *v-c { + } else { + panic("bad") + } +} + +func gt_f2() { + const c = 10 + var a = 0 + var v *int = &a + if len([]int{}) > *v|0x0f+c { + panic("bad") + } +} + +func gt_f3() { + const c int32 = 10 + var a int32 = 0 + var v *int32 = &a + if int32(len([]int{})) > *v|0x0f+c { + panic("bad") + } +} + +func le_f1() { + const c = -10 + var a = 0 + var v *int = &a + if *v|0xff+c <= len([]int{}) { + panic("bad") + } +} + +func le_f2() { + const c = 0xf + var a = 0 + var v *int = &a + if *v|0xf-c <= len([]int{}) { + } else { + panic("bad") + } +} + +func le_f3() { + const c int32 = -10 + var a int32 = 0 + var v *int32 = &a + if *v|0xff+c <= int32(len([]int{})) { + panic("bad") + } +} + +func ge_f1() { + const c = -10 + var a = 0 + var v *int = &a + if len([]int{}) >= *v|0xff+c { + panic("bad") + } +} + +func ge_f2() { + const c int32 = 10 + var a int32 = 0 + var v *int32 = &a + if int32(len([]int{})) >= *v|0x0f+c { + panic("bad") + } +} + +func ge_f3() { + const c = -10 + var a = 0 + var v *int = &a + if len([]int{}) >= *v|0x0a+c { + } else { + panic("bad") + } +} diff --git a/test/fixedbugs/issue41247.go b/test/fixedbugs/issue41247.go new file mode 100644 index 0000000000..2df919c9e6 --- /dev/null +++ b/test/fixedbugs/issue41247.go @@ -0,0 +1,11 @@ +// errorcheck + +// 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 + +func f() [2]int { + return [...]int{2: 0} // ERROR "cannot use \[\.\.\.\]int literal \(type \[3\]int\)" +} diff --git a/test/fixedbugs/issue8606b.go b/test/fixedbugs/issue8606b.go new file mode 100644 index 0000000000..448ea566f0 --- /dev/null +++ b/test/fixedbugs/issue8606b.go @@ -0,0 +1,63 @@ +// run + +// 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. + +// This is an optimization check. We want to make sure that we compare +// string lengths, and other scalar fields, before checking string +// contents. There's no way to verify this in the language, and +// codegen tests in test/codegen can't really detect ordering +// optimizations like this. Instead, we generate invalid strings with +// bad backing store pointers but nonzero length, so we can check that +// the backing store never gets compared. +// +// We use two different bad strings so that pointer comparisons of +// backing store pointers fail. + +package main + +import ( + "fmt" + "reflect" + "unsafe" +) + +func bad1() string { + s := "foo" + (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = 1 // write bad value to data ptr + return s +} +func bad2() string { + s := "foo" + (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = 2 // write bad value to data ptr + return s +} + +type SI struct { + s string + i int +} + +type SS struct { + s string + t string +} + +func main() { + for _, test := range []struct { + a, b interface{} + }{ + {SI{s: bad1(), i: 1}, SI{s: bad2(), i: 2}}, + {SS{s: bad1(), t: "a"}, SS{s: bad2(), t: "aa"}}, + {SS{s: "a", t: bad1()}, SS{s: "b", t: bad2()}}, + // This one would panic because the length of both strings match, and we check + // the body of the bad strings before the body of the good strings. + //{SS{s: bad1(), t: "a"}, SS{s: bad2(), t: "b"}}, + } { + if test.a == test.b { + panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b)) + } + } + +} diff --git a/test/notinheap2.go b/test/notinheap2.go index 944f2993ab..de1e6db1d3 100644 --- a/test/notinheap2.go +++ b/test/notinheap2.go @@ -13,12 +13,14 @@ type nih struct { next *nih } -// Globals and stack variables are okay. +// Global variables are okay. var x nih +// Stack variables are not okay. + func f() { - var y nih + var y nih // ERROR "nih is go:notinheap; stack allocation disallowed" x = y } @@ -26,11 +28,17 @@ func f() { var y *nih var z []nih +var w []nih +var n int func g() { y = new(nih) // ERROR "heap allocation disallowed" z = make([]nih, 1) // ERROR "heap allocation disallowed" z = append(z, x) // ERROR "heap allocation disallowed" + // Test for special case of OMAKESLICECOPY + x := make([]nih, n) // ERROR "heap allocation disallowed" + copy(x, z) + z = x } // Writes don't produce write barriers. diff --git a/test/runtime.go b/test/runtime.go index 0cf781b814..bccc9b53af 100644 --- a/test/runtime.go +++ b/test/runtime.go @@ -17,5 +17,5 @@ package main import "runtime" func main() { - runtime.printbool(true) // ERROR "unexported" "undefined" + runtime.printbool(true) // ERROR "unexported" } |