diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bigmap.go | 105 | ||||
-rw-r--r-- | test/fixedbugs/bug441.go | 36 | ||||
-rw-r--r-- | test/fixedbugs/bug442.go | 27 | ||||
-rw-r--r-- | test/fixedbugs/bug443.go | 17 | ||||
-rw-r--r-- | test/fixedbugs/bug444.go | 19 | ||||
-rw-r--r-- | test/index.go | 73 | ||||
-rw-r--r-- | test/map1.go | 18 | ||||
-rw-r--r-- | test/range.go | 11 |
8 files changed, 291 insertions, 15 deletions
diff --git a/test/bigmap.go b/test/bigmap.go index 37e049846..c5e4f91e1 100644 --- a/test/bigmap.go +++ b/test/bigmap.go @@ -4,7 +4,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Test behavior of maps with large elements. +// Internally a map holds elements in up to 255 bytes of key+value. +// When key or value or both are too large, it uses pointers to key+value +// instead. Test all the combinations. package main @@ -33,4 +35,105 @@ func main() { cmp(m[1], seq(11, 13)) cmp(m[2], seq(2, 9)) cmp(m[3], seq(3, 17)) + + + { + type T [1]byte + type V [1]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [100]byte + type V [1]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [1]byte + type V [100]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [1000]byte + type V [1]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [1]byte + type V [1000]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [1000]byte + type V [1000]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [200]byte + type V [1]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [1]byte + type V [200]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } + { + type T [200]byte + type V [200]byte + m := make(map[T]V) + m[T{}] = V{1} + m[T{1}] = V{2} + if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 { + println(x, y) + panic("bad map") + } + } } diff --git a/test/fixedbugs/bug441.go b/test/fixedbugs/bug441.go new file mode 100644 index 000000000..8562bfeef --- /dev/null +++ b/test/fixedbugs/bug441.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2012 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. + +// Was discarding function calls made for arguments named _ +// in inlined functions. Issue 3593. + +package main + +var did int + +func main() { + foo(side()) + foo2(side(), side()) + foo3(side(), side()) + T.m1(T(side())) + T(1).m2(side()) + const want = 7 + if did != want { + println("BUG: missing", want-did, "calls") + } +} + +func foo(_ int) {} +func foo2(_, _ int) {} +func foo3(int, int) {} +type T int +func (_ T) m1() {} +func (t T) m2(_ int) {} + +func side() int { + did++ + return 1 +} diff --git a/test/fixedbugs/bug442.go b/test/fixedbugs/bug442.go new file mode 100644 index 000000000..1d1a94816 --- /dev/null +++ b/test/fixedbugs/bug442.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2012 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. + +// Used to crash generating hash and == functions for struct +// with leading _ field. Issue 3607. + +package main + +type T struct { + _ int + X interface{} + _ string + Y float64 +} + +func main() { + m := map[T]int{} + m[T{X: 1, Y: 2}] = 1 + m[T{X: 2, Y: 3}] = 2 + m[T{X: 1, Y: 2}] = 3 // overwrites first entry + if len(m) != 2 { + println("BUG") + } +} diff --git a/test/fixedbugs/bug443.go b/test/fixedbugs/bug443.go new file mode 100644 index 000000000..b67bd8cb8 --- /dev/null +++ b/test/fixedbugs/bug443.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2012 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. + +// Was failing to compile with 'invalid receiver' due to +// incomplete type definition evaluation. Issue 3709. + +package p + +type T1 struct { F *T2 } +type T2 T1 + +type T3 T2 +func (*T3) M() // was invalid receiver + diff --git a/test/fixedbugs/bug444.go b/test/fixedbugs/bug444.go new file mode 100644 index 000000000..0bbd16fae --- /dev/null +++ b/test/fixedbugs/bug444.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2012 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 no-op conversion here used to confuse the compiler +// into doing a load-effective-address of nil. + +package main + +import "reflect" + +type T interface {} + +func main() { + reflect.TypeOf(nil) + reflect.TypeOf(T(nil)) // used to fail +} diff --git a/test/index.go b/test/index.go index eb0c45495..f9e2413c1 100644 --- a/test/index.go +++ b/test/index.go @@ -31,16 +31,20 @@ import ( type quad struct { x, y, z, w int } const ( - cj = 11 - ci int = 12 - ci32 int32 = 13 - ci64 int64 = 14 + cj = 100011 + ci int = 100012 + ci8 int8 = 115 + ci16 int16 = 10016 + ci32 int32 = 100013 + ci64 int64 = 100014 ci64big int64 = 1<<31 ci64bigger int64 = 1<<32 chuge = 1<<100 cnj = -2 cni int = -3 + cni8 int8 = -6 + cni16 int16 = -7 cni32 int32 = -4 cni64 int64 = -5 cni64big int64 = -1<<31 @@ -48,16 +52,20 @@ const ( cnhuge = -1<<100 ) -var j int = 20 -var i int = 21 -var i32 int32 = 22 -var i64 int64 = 23 +var j int = 100020 +var i int = 100021 +var i8 int8 = 126 +var i16 int16 = 10025 +var i32 int32 = 100022 +var i64 int64 = 100023 var i64big int64 = 1<<31 var i64bigger int64 = 1<<32 var huge uint64 = 1<<64 - 1 var nj int = -10 var ni int = -11 +var ni8 int8 = -14 +var ni16 int16 = -15 var ni32 int32 = -12 var ni64 int64 = -13 var ni64big int64 = -1<<31 @@ -72,6 +80,14 @@ var sq []quad = make([]quad, 10) var aq [10]quad var paq *[10]quad = &aq +var sib []int = make([]int, 100000) +var aib [100000]int +var paib *[100000]int = &aib + +var sqb []quad = make([]quad, 100000) +var aqb [100000]quad +var paqb *[100000]quad = &aqb + type T struct { si []int ai [10]int @@ -79,11 +95,18 @@ type T struct { sq []quad aq [10]quad paq *[10]quad + + sib []int + aib [100000]int + paib *[100000]int + sqb []quad + aqb [100000]quad + paqb *[100000]quad } -var t = T{si, ai, pai, sq, aq, paq} +var t = T{si, ai, pai, sq, aq, paq, sib, aib, paib, sqb, aqb, paqb} -var pt = &T{si, ai, pai, sq, aq, paq} +var pt = &T{si, ai, pai, sq, aq, paq, sib, aib, paib, sqb, aqb, paqb} // test that f panics func test(f func(), s string) { @@ -92,11 +115,25 @@ func test(f func(), s string) { _, file, line, _ := runtime.Caller(2) bug() print(file, ":", line, ": ", s, " did not panic\n") + } else if !contains(err.(error).Error(), "out of range") { + _, file, line, _ := runtime.Caller(2) + bug() + print(file, ":", line, ": ", s, " unexpected panic: ", err.(error).Error(), "\n") } }() f() } +func contains(x, y string) bool { + for i := 0; i+len(y) <= len(x); i++ { + if x[i:i+len(y)] == y { + return true + } + } + return false +} + + var X interface{} func use(y interface{}) { X = y @@ -147,11 +184,14 @@ func main() { // Array, pointer to array, slice. []string{"a", "pa", "s"}, - + // Element is int, element is quad (struct). // This controls whether we end up in gsubr.c (i) or cgen.c (q). []string{"i", "q"}, + // Small or big len. + []string{"", "b"}, + // Variable or constant. []string{"", "c"}, @@ -159,11 +199,11 @@ func main() { []string{"", "n"}, // Size of index. - []string{"j", "i", "i32", "i64", "i64big", "i64bigger", "huge"}, + []string{"j", "i", "i8", "i16", "i32", "i64", "i64big", "i64bigger", "huge"}, } forall(choices, func(x []string) { - p, a, e, c, n, i := x[0], x[1], x[2], x[3], x[4], x[5] + p, a, e, big, c, n, i := x[0], x[1], x[2], x[3], x[4], x[5], x[6] // Pass: dynamic=0, static=1, 2. // Which cases should be caught statically? @@ -185,10 +225,15 @@ func main() { thisPass = 2 } } + + // If we're using the big-len data, positive int8 and int16 cannot overflow. + if big == "b" && n == "" && (i == "i8" || i == "i16") { + return + } // Only print the test case if it is appropriate for this pass. if thisPass == *pass { - pae := p+a+e + pae := p+a+e+big cni := c+n+i // Index operation diff --git a/test/map1.go b/test/map1.go index 369e49da5..6f1a1c8ac 100644 --- a/test/map1.go +++ b/test/map1.go @@ -41,4 +41,22 @@ var ( _ map[[]int]v // ERROR "invalid map key" _ map[func()]v // ERROR "invalid map key" _ map[map[int]int]v // ERROR "invalid map key" + _ map[T1]v // ERROR "invalid map key" + _ map[T2]v // ERROR "invalid map key" + _ map[T3]v // ERROR "invalid map key" + _ map[T4]v // ERROR "invalid map key" + _ map[T5]v + _ map[T6]v + _ map[T7]v + _ map[T8]v ) + +type T1 []int +type T2 struct { F T1 } +type T3 []T4 +type T4 struct { F T3 } + +type T5 *int +type T6 struct { F T5 } +type T7 *T4 +type T8 struct { F *T7 } diff --git a/test/range.go b/test/range.go index b0f3ae605..68b0c9a2f 100644 --- a/test/range.go +++ b/test/range.go @@ -58,6 +58,17 @@ func testslice() { println("wrong sum ranging over makeslice") panic("fail") } + + x := []int{10, 20} + y := []int{99} + i := 1 + for i, x[i] = range y { + break + } + if i != 0 || x[0] != 10 || x[1] != 99 { + println("wrong parallel assignment", i, x[0], x[1]) + panic("fail") + } } func testslice1() { |