diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /test/fixedbugs | |
parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
download | golang-51f2ca399fb8da86b2e7b3a0582e083fab731a98.tar.gz |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'test/fixedbugs')
115 files changed, 2339 insertions, 72 deletions
diff --git a/test/fixedbugs/bug176.go b/test/fixedbugs/bug176.go index 82f8dba0a..ea3a90974 100644 --- a/test/fixedbugs/bug176.go +++ b/test/fixedbugs/bug176.go @@ -9,6 +9,6 @@ package main var x int var a = []int{ x: 1} // ERROR "constant" -var b = [...]int{ x : 1} // ERROR "constant" +var b = [...]int{x: 1} var c = map[int]int{ x: 1} diff --git a/test/fixedbugs/bug191.dir/a.go b/test/fixedbugs/bug191.dir/a.go index b87ad6f4f..139a8a3a2 100644 --- a/test/fixedbugs/bug191.dir/a.go +++ b/test/fixedbugs/bug191.dir/a.go @@ -4,8 +4,10 @@ package a +var A int + func init() { - println("a"); + A = 1 } type T int; diff --git a/test/fixedbugs/bug191.dir/b.go b/test/fixedbugs/bug191.dir/b.go index 3e780ac0d..36770f6fc 100644 --- a/test/fixedbugs/bug191.dir/b.go +++ b/test/fixedbugs/bug191.dir/b.go @@ -4,8 +4,10 @@ package b +var B int + func init() { - println("b"); + B = 2 } type V int; diff --git a/test/fixedbugs/bug191.dir/main.go b/test/fixedbugs/bug191.dir/main.go index 995134ccf..2d24dd12d 100644 --- a/test/fixedbugs/bug191.dir/main.go +++ b/test/fixedbugs/bug191.dir/main.go @@ -11,4 +11,7 @@ var _ T var _ V func main() { + if A != 1 || B != 2 { + panic("wrong vars") + } } diff --git a/test/fixedbugs/bug191.go b/test/fixedbugs/bug191.go index acb4796b3..248e23edf 100644 --- a/test/fixedbugs/bug191.go +++ b/test/fixedbugs/bug191.go @@ -1,4 +1,4 @@ -// rundircmpout +// rundir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug191.out b/test/fixedbugs/bug191.out deleted file mode 100644 index 0e1677a97..000000000 --- a/test/fixedbugs/bug191.out +++ /dev/null @@ -1,2 +0,0 @@ -b -a diff --git a/test/fixedbugs/bug385_32.go b/test/fixedbugs/bug385_32.go index 724ed9326..daf2a083c 100644 --- a/test/fixedbugs/bug385_32.go +++ b/test/fixedbugs/bug385_32.go @@ -1,4 +1,4 @@ -// +build 386 arm +// +build 386 amd64p32 arm // errorcheck // Copyright 2011 The Go Authors. All rights reserved. @@ -9,7 +9,7 @@ package main func main() { - var arr [1000200030]int // ERROR "type .* too large" + var arr [1000200030]int // GC_ERROR "type .* too large" arr_bkup := arr _ = arr_bkup } diff --git a/test/fixedbugs/bug385_64.go b/test/fixedbugs/bug385_64.go index aef03c389..6789c0abf 100644 --- a/test/fixedbugs/bug385_64.go +++ b/test/fixedbugs/bug385_64.go @@ -12,7 +12,7 @@ package main var z [10<<20]byte -func main() { // ERROR "stack frame too large" +func main() { // GC_ERROR "stack frame too large" // seq 1 206 | sed 's/.*/ var x& [10<<20]byte; z = x&/' var x1 [10<<20]byte; z = x1 var x2 [10<<20]byte; z = x2 diff --git a/test/fixedbugs/bug462.go b/test/fixedbugs/bug462.go index 6434255c8..1a23ad064 100644 --- a/test/fixedbugs/bug462.go +++ b/test/fixedbugs/bug462.go @@ -14,6 +14,6 @@ type T struct { func main() { _ = T { - os.File: 1, // ERROR "unknown T field" + os.File: 1, // ERROR "unknown T? ?field" } } diff --git a/test/fixedbugs/bug476.go b/test/fixedbugs/bug476.go index 4ea217404..563fd9156 100644 --- a/test/fixedbugs/bug476.go +++ b/test/fixedbugs/bug476.go @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file. // Logical operation on named boolean type returns the same type, -// supporting an implicit convertion to an interface type. This used +// supporting an implicit conversion to an interface type. This used // to crash gccgo. package p diff --git a/test/fixedbugs/bug480.dir/a.go b/test/fixedbugs/bug480.dir/a.go new file mode 100644 index 000000000..6dff51586 --- /dev/null +++ b/test/fixedbugs/bug480.dir/a.go @@ -0,0 +1,17 @@ +// Copyright 2013 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 + +type S interface{ + F() T +} + +type T struct { + S +} + +type U struct { + error +} diff --git a/test/fixedbugs/bug480.dir/b.go b/test/fixedbugs/bug480.dir/b.go new file mode 100644 index 000000000..620736540 --- /dev/null +++ b/test/fixedbugs/bug480.dir/b.go @@ -0,0 +1,13 @@ +// Copyright 2013 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 b + +import "./a" + +var t a.T + +func F() error { + return a.U{} +} diff --git a/test/fixedbugs/bug480.go b/test/fixedbugs/bug480.go new file mode 100644 index 000000000..5b44af430 --- /dev/null +++ b/test/fixedbugs/bug480.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2013 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 an import of a forward declared type. + +package ignored diff --git a/test/fixedbugs/bug481.go b/test/fixedbugs/bug481.go new file mode 100644 index 000000000..d0922a5a4 --- /dev/null +++ b/test/fixedbugs/bug481.go @@ -0,0 +1,18 @@ +// compile + +// Copyright 2013 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. + +// Returning an index into a conversion from string to slice caused a +// compilation error when using gccgo. + +package p + +func F1(s string) byte { + return []byte(s)[0] +} + +func F2(s string) rune { + return []rune(s)[0] +} diff --git a/test/fixedbugs/bug482.go b/test/fixedbugs/bug482.go new file mode 100644 index 000000000..10c48287d --- /dev/null +++ b/test/fixedbugs/bug482.go @@ -0,0 +1,20 @@ +// compile + +// Copyright 2013 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. + +// Using the same name for a field in a composite literal and for a +// global variable that depends on the variable being initialized +// caused gccgo to erroneously report "variable initializer refers to +// itself". + +package p + +type S struct { + F int +} + +var V = S{F: 1} + +var F = V.F diff --git a/test/fixedbugs/bug483.go b/test/fixedbugs/bug483.go new file mode 100644 index 000000000..2372e89a7 --- /dev/null +++ b/test/fixedbugs/bug483.go @@ -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/test/fixedbugs/bug484.go b/test/fixedbugs/bug484.go new file mode 100644 index 000000000..c664b83af --- /dev/null +++ b/test/fixedbugs/bug484.go @@ -0,0 +1,90 @@ +// 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" + +var c bool + +func f() interface{} { + if c { // disable inlining + f() + } + runtime.GC() + return nil +} + +func g() { + if c { // disable inlining + g() + } + var s interface{} + _ = func() { + s := f() + _ = s + } + s = f() + useiface(s) + useiface(s) +} + +func useiface(x interface{}) { + if c { // disable inlining + useiface(x) + } +} + +func h() { + if c { // disable inlining + h() + } + var x [16]uintptr + for i := range x { + x[i] = 1 + } + + useint(x[0]) + useint(x[1]) + useint(x[2]) + useint(x[3]) +} + +func useint(x uintptr) { + if c { // disable inlining + useint(x) + } +} + +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/test/fixedbugs/bug485.go b/test/fixedbugs/bug485.go new file mode 100644 index 000000000..1544753ab --- /dev/null +++ b/test/fixedbugs/bug485.go @@ -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/test/fixedbugs/issue1304.go b/test/fixedbugs/issue1304.go new file mode 100644 index 000000000..1206e1840 --- /dev/null +++ b/test/fixedbugs/issue1304.go @@ -0,0 +1,23 @@ +// 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. + +package main + +var a = 1 + +func main() { + defer func() { + recover() + if a != 2 { + println("BUG a =", a) + } + }() + a = 2 + b := a - a + c := 4 + a = c / b + a = 3 +} diff --git a/test/fixedbugs/issue3705.go b/test/fixedbugs/issue3705.go index c19bcea1c..64ef38b10 100644 --- a/test/fixedbugs/issue3705.go +++ b/test/fixedbugs/issue3705.go @@ -6,4 +6,4 @@ package p -func init() // ERROR "missing function body" +func init() // ERROR "missing function body|cannot declare init" diff --git a/test/fixedbugs/issue4251.go b/test/fixedbugs/issue4251.go index 4adec2bab..3668d4c89 100644 --- a/test/fixedbugs/issue4251.go +++ b/test/fixedbugs/issue4251.go @@ -9,13 +9,13 @@ package p func F1(s []byte) []byte { - return s[2:1] // ERROR "invalid slice index" + return s[2:1] // ERROR "invalid slice index|inverted slice range" } func F2(a [10]byte) []byte { - return a[2:1] // ERROR "invalid slice index" + return a[2:1] // ERROR "invalid slice index|inverted slice range" } func F3(s string) string { - return s[2:1] // ERROR "invalid slice index" + return s[2:1] // ERROR "invalid slice index|inverted slice range" } diff --git a/test/fixedbugs/issue4388.go b/test/fixedbugs/issue4388.go new file mode 100644 index 000000000..2e052e138 --- /dev/null +++ b/test/fixedbugs/issue4388.go @@ -0,0 +1,56 @@ +// 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. + +package main + +import ( + "fmt" + "io" + "runtime" +) + +type T struct { + io.Closer +} + +func f1() { + // The 4 here and below depends on the number of internal runtime frames + // that sit between a deferred function called during panic and + // the original frame. If that changes, this test will start failing and + // the number here will need to be updated. + defer checkLine(4) + var t *T + var c io.Closer = t + c.Close() +} + +func f2() { + defer checkLine(4) + var t T + var c io.Closer = t + c.Close() +} + +func main() { + f1() + f2() +} + +func checkLine(n int) { + if err := recover(); err == nil { + panic("did not panic") + } + var file string + var line int + for i := 1; i <= n; i++ { + _, file, line, _ = runtime.Caller(i) + if file != "<autogenerated>" || line != 1 { + continue + } + return + } + panic(fmt.Sprintf("expected <autogenerated>:1 have %s:%d", file, line)) +} diff --git a/test/fixedbugs/issue4405.go b/test/fixedbugs/issue4405.go index c0d808559..b8458d776 100644 --- a/test/fixedbugs/issue4405.go +++ b/test/fixedbugs/issue4405.go @@ -8,8 +8,8 @@ package p const ( _ = iota - _ // ERROR "illegal character" - _ // ERROR "illegal character" - _ // ERROR "illegal character" - _ // ERROR "illegal character" + _ // ERROR "illegal character|invalid character" + _ // ERROR "illegal character|invalid character" + _ // ERROR "illegal character|invalid character" + _ // ERROR "illegal character|invalid character" ) diff --git a/test/fixedbugs/issue4429.go b/test/fixedbugs/issue4429.go index 8a93b0204..6822760ef 100644 --- a/test/fixedbugs/issue4429.go +++ b/test/fixedbugs/issue4429.go @@ -12,5 +12,5 @@ type a struct { func main() { av := a{}; - *a(av); // ERROR "invalid indirect" + _ = *a(av); // ERROR "invalid indirect|expected pointer" } diff --git a/test/fixedbugs/issue4510.dir/f1.go b/test/fixedbugs/issue4510.dir/f1.go index 1e642e4ce..7e2cffa5d 100644 --- a/test/fixedbugs/issue4510.dir/f1.go +++ b/test/fixedbugs/issue4510.dir/f1.go @@ -4,6 +4,6 @@ package p -import "fmt" // ERROR "fmt redeclared" +import "fmt" // ERROR "fmt redeclared|imported" var _ = fmt.Printf diff --git a/test/fixedbugs/issue4517d.go b/test/fixedbugs/issue4517d.go index f601db66f..3d727d433 100644 --- a/test/fixedbugs/issue4517d.go +++ b/test/fixedbugs/issue4517d.go @@ -6,4 +6,4 @@ package p -import init "fmt" // ERROR "cannot import package as init - init must be a func" +import init "fmt" // ERROR "cannot import package as init" diff --git a/test/fixedbugs/issue4545.go b/test/fixedbugs/issue4545.go index 501caadb0..c37ccef7c 100644 --- a/test/fixedbugs/issue4545.go +++ b/test/fixedbugs/issue4545.go @@ -13,7 +13,7 @@ import "fmt" func main() { var s uint - fmt.Println(1.0 + 1<<s) // ERROR "invalid operation|non-integer type" + fmt.Println(1.0 + 1<<s) // ERROR "invalid operation|non-integer type|incompatible type" x := 1.0 + 1<<s // ERROR "invalid operation|non-integer type" _ = x } diff --git a/test/fixedbugs/issue4610.go b/test/fixedbugs/issue4610.go index bc6bfe790..d56c6d3e8 100644 --- a/test/fixedbugs/issue4610.go +++ b/test/fixedbugs/issue4610.go @@ -12,6 +12,6 @@ type bar struct { func main() { var foo bar - _ = &foo{} // ERROR "is not a type" -} + _ = &foo{} // ERROR "is not a type|expected .;." +} // GCCGO_ERROR "expected declaration" diff --git a/test/fixedbugs/issue4618.go b/test/fixedbugs/issue4618.go index 335feaadb..fe875b350 100644 --- a/test/fixedbugs/issue4618.go +++ b/test/fixedbugs/issue4618.go @@ -9,6 +9,7 @@ package main import ( "fmt" "os" + "runtime" "testing" ) @@ -29,11 +30,11 @@ func G() { func main() { nf := testing.AllocsPerRun(100, F) ng := testing.AllocsPerRun(100, G) - if int(nf) != 1 { + if int(nf) > 1 { fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) os.Exit(1) } - if int(ng) != 0 { + if int(ng) != 0 && (runtime.Compiler != "gccgo" || int(ng) != 1) { fmt.Printf("AllocsPerRun(100, G) = %v, want 0\n", ng) os.Exit(1) } diff --git a/test/fixedbugs/issue4654.go b/test/fixedbugs/issue4654.go index 170594e4b..d3f582b20 100644 --- a/test/fixedbugs/issue4654.go +++ b/test/fixedbugs/issue4654.go @@ -12,32 +12,32 @@ package p import "unsafe" func f() { - defer int(0) // ERROR "defer requires function call, not conversion" - go string([]byte("abc")) // ERROR "go requires function call, not conversion" + defer int(0) // ERROR "defer requires function call, not conversion|is not used" + go string([]byte("abc")) // ERROR "go requires function call, not conversion|is not used" var c complex128 var f float64 var t struct {X int} var x []int - defer append(x, 1) // ERROR "defer discards result of append" - defer cap(x) // ERROR "defer discards result of cap" - defer complex(1, 2) // ERROR "defer discards result of complex" - defer complex(f, 1) // ERROR "defer discards result of complex" - defer imag(1i) // ERROR "defer discards result of imag" - defer imag(c) // ERROR "defer discards result of imag" - defer len(x) // ERROR "defer discards result of len" - defer make([]int, 1) // ERROR "defer discards result of make" - defer make(chan bool) // ERROR "defer discards result of make" - defer make(map[string]int) // ERROR "defer discards result of make" - defer new(int) // ERROR "defer discards result of new" - defer real(1i) // ERROR "defer discards result of real" - defer real(c) // ERROR "defer discards result of real" - defer append(x, 1) // ERROR "defer discards result of append" - defer append(x, 1) // ERROR "defer discards result of append" - defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof" - defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof" - defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof" + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer cap(x) // ERROR "defer discards result of cap|is not used" + defer complex(1, 2) // ERROR "defer discards result of complex|is not used" + defer complex(f, 1) // ERROR "defer discards result of complex|is not used" + defer imag(1i) // ERROR "defer discards result of imag|is not used" + defer imag(c) // ERROR "defer discards result of imag|is not used" + defer len(x) // ERROR "defer discards result of len|is not used" + defer make([]int, 1) // ERROR "defer discards result of make|is not used" + defer make(chan bool) // ERROR "defer discards result of make|is not used" + defer make(map[string]int) // ERROR "defer discards result of make|is not used" + defer new(int) // ERROR "defer discards result of new|is not used" + defer real(1i) // ERROR "defer discards result of real|is not used" + defer real(c) // ERROR "defer discards result of real|is not used" + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer append(x, 1) // ERROR "defer discards result of append|is not used" + defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof|is not used" + defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof|is not used" + defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof|is not used" defer copy(x, x) // ok m := make(map[int]int) @@ -47,8 +47,8 @@ func f() { defer println(1) // ok defer recover() // ok - int(0) // ERROR "int\(0\) evaluated but not used" - string([]byte("abc")) // ERROR "string\(.*\) evaluated but not used" + int(0) // ERROR "int\(0\) evaluated but not used|is not used" + string([]byte("abc")) // ERROR "string\(.*\) evaluated but not used|is not used" append(x, 1) // ERROR "not used" cap(x) // ERROR "not used" diff --git a/test/fixedbugs/issue4667.go b/test/fixedbugs/issue4667.go index 3a00a3195..18d773c2c 100644 --- a/test/fixedbugs/issue4667.go +++ b/test/fixedbugs/issue4667.go @@ -26,11 +26,11 @@ func F() { func main() { nf := testing.AllocsPerRun(100, F) ng := testing.AllocsPerRun(100, G) - if int(nf) != 1 { + if int(nf) > 1 { fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) os.Exit(1) } - if int(ng) != 1 { + if int(ng) > 1 { fmt.Printf("AllocsPerRun(100, G) = %v, want 1\n", ng) os.Exit(1) } diff --git a/test/fixedbugs/issue4776.go b/test/fixedbugs/issue4776.go index c38dc09b1..13781af1f 100644 --- a/test/fixedbugs/issue4776.go +++ b/test/fixedbugs/issue4776.go @@ -6,5 +6,5 @@ // Issue 4776: missing package declaration error should be fatal. -type MyInt int32 // ERROR "package statement must be first" +type MyInt int32 // ERROR "package statement must be first|package clause" diff --git a/test/fixedbugs/issue4813.go b/test/fixedbugs/issue4813.go index 20dc58795..f560b2fac 100644 --- a/test/fixedbugs/issue4813.go +++ b/test/fixedbugs/issue4813.go @@ -28,25 +28,25 @@ var ( var ( a1 = A[i] a2 = A[f] - a3 = A[f2] // ERROR "truncated" + a3 = A[f2] // ERROR "truncated|must be integer" a4 = A[c] - a5 = A[c2] // ERROR "truncated" + a5 = A[c2] // ERROR "truncated|must be integer" a6 = A[vf] // ERROR "non-integer|must be integer" a7 = A[vc] // ERROR "non-integer|must be integer" s1 = S[i] s2 = S[f] - s3 = S[f2] // ERROR "truncated" + s3 = S[f2] // ERROR "truncated|must be integer" s4 = S[c] - s5 = S[c2] // ERROR "truncated" + s5 = S[c2] // ERROR "truncated|must be integer" s6 = S[vf] // ERROR "non-integer|must be integer" s7 = S[vc] // ERROR "non-integer|must be integer" t1 = T[i] t2 = T[f] - t3 = T[f2] // ERROR "truncated" + t3 = T[f2] // ERROR "truncated|must be integer" t4 = T[c] - t5 = T[c2] // ERROR "truncated" + t5 = T[c2] // ERROR "truncated|must be integer" t6 = T[vf] // ERROR "non-integer|must be integer" t7 = T[vc] // ERROR "non-integer|must be integer" ) diff --git a/test/fixedbugs/issue4847.go b/test/fixedbugs/issue4847.go index a99e80129..91a6568f2 100644 --- a/test/fixedbugs/issue4847.go +++ b/test/fixedbugs/issue4847.go @@ -19,6 +19,6 @@ func matchList(s *S) E { return matcher(matchAnyFn)(s) } var foo = matcher(matchList) -var matchAny = matcher(matchList) // ERROR "initialization loop" +var matchAny = matcher(matchList) // ERROR "initialization loop|depends upon itself" func matchAnyFn(s *S) (err E) { return matchAny(s) } diff --git a/test/fixedbugs/issue5089.go b/test/fixedbugs/issue5089.go index 14d6bde98..81b9f0521 100644 --- a/test/fixedbugs/issue5089.go +++ b/test/fixedbugs/issue5089.go @@ -8,8 +8,8 @@ package p -import "bufio" +import "bufio" // GCCGO_ERROR "previous" -func (b *bufio.Reader) Buffered() int { // ERROR "non-local" +func (b *bufio.Reader) Buffered() int { // ERROR "non-local|redefinition" return -1 } diff --git a/test/fixedbugs/issue5172.go b/test/fixedbugs/issue5172.go index 2dd542a5d..a6acbd3db 100644 --- a/test/fixedbugs/issue5172.go +++ b/test/fixedbugs/issue5172.go @@ -14,6 +14,6 @@ type foo struct { func main() { var f foo - go f.bar() - defer f.bar() + go f.bar() // GCCGO_ERROR "undefined" + defer f.bar() // GCCGO_ERROR "undefined" } diff --git a/test/fixedbugs/issue5358.go b/test/fixedbugs/issue5358.go index 75aa9533d..c2b1da9e0 100644 --- a/test/fixedbugs/issue5358.go +++ b/test/fixedbugs/issue5358.go @@ -13,5 +13,5 @@ func f(x int, y ...int) {} func g() (int, []int) func main() { - f(g()) // ERROR "as type int in" + f(g()) // ERROR "as type int in|incompatible type" } diff --git a/test/fixedbugs/issue5493.go b/test/fixedbugs/issue5493.go index affc07b58..2ee0398af 100644 --- a/test/fixedbugs/issue5493.go +++ b/test/fixedbugs/issue5493.go @@ -31,9 +31,10 @@ func run() error { } func main() { - // Does not work on 32-bits due to partially conservative GC. + // Does not work on 32-bits, or with gccgo, due to partially + // conservative GC. // Try to enable when we have fully precise GC. - if runtime.GOARCH != "amd64" { + if runtime.GOARCH != "amd64" || runtime.Compiler == "gccgo" { return } count = N diff --git a/test/fixedbugs/issue5581.go b/test/fixedbugs/issue5581.go index 8c2d59729..36a4ad671 100644 --- a/test/fixedbugs/issue5581.go +++ b/test/fixedbugs/issue5581.go @@ -26,7 +26,7 @@ type Foo struct { type Bar struct { A *Foo - B chan Blah // ERROR "undefined: Blah" + B chan Blah // ERROR "undefined.*Blah" } func main() { diff --git a/test/fixedbugs/issue5793.go b/test/fixedbugs/issue5793.go new file mode 100644 index 000000000..f5a9965f2 --- /dev/null +++ b/test/fixedbugs/issue5793.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2013 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. + +// Issue 5793: calling 2-arg builtin with multiple-result f() call expression gives +// spurious error. + +package main + +func complexArgs() (float64, float64) { + return 5, 7 +} + +func appendArgs() ([]string, string) { + return []string{"foo"}, "bar" +} + +func appendMultiArgs() ([]byte, byte, byte) { + return []byte{'a', 'b'}, '1', '2' +} + +func main() { + if c := complex(complexArgs()); c != 5+7i { + panic(c) + } + + if s := append(appendArgs()); len(s) != 2 || s[0] != "foo" || s[1] != "bar" { + panic(s) + } + + if b := append(appendMultiArgs()); len(b) != 4 || b[0] != 'a' || b[1] != 'b' || b[2] != '1' || b[3] != '2' { + panic(b) + } +} diff --git a/test/fixedbugs/issue5957.dir/c.go b/test/fixedbugs/issue5957.dir/c.go index 42c88177b..a1781d4d4 100644 --- a/test/fixedbugs/issue5957.dir/c.go +++ b/test/fixedbugs/issue5957.dir/c.go @@ -1,12 +1,12 @@ package p import ( - "./a" // ERROR "imported and not used: \x22a\x22 as surprise" - "./b" // ERROR "imported and not used: \x22b\x22 as surprise2" - b "./b" // ERROR "imported and not used: \x22b\x22$" - foo "math" // ERROR "imported and not used: \x22math\x22 as foo" + "./a" // ERROR "imported and not used: \x22a\x22 as surprise|imported and not used: surprise" + "./b" // GC_ERROR "imported and not used: \x22b\x22 as surprise2|imported and not used: surprise2" + b "./b" // ERROR "imported and not used: \x22b\x22$|imported and not used: surprise2" + foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math" "fmt" // actually used - "strings" // ERROR "imported and not used: \x22strings\x22" + "strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings" ) var _ = fmt.Printf diff --git a/test/fixedbugs/issue6295.dir/p0.go b/test/fixedbugs/issue6295.dir/p0.go new file mode 100644 index 000000000..cf86fbcb5 --- /dev/null +++ b/test/fixedbugs/issue6295.dir/p0.go @@ -0,0 +1,13 @@ +// Copyright 2013 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 p0 + +type T0 interface { + m0() +} + +type S0 struct{} + +func (S0) m0() {} diff --git a/test/fixedbugs/issue6295.dir/p1.go b/test/fixedbugs/issue6295.dir/p1.go new file mode 100644 index 000000000..974d02fb0 --- /dev/null +++ b/test/fixedbugs/issue6295.dir/p1.go @@ -0,0 +1,26 @@ +// Copyright 2013 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 p1 + +import "./p0" + +type T1 interface { + p0.T0 + m1() +} + +type S1 struct { + p0.S0 +} + +func (S1) m1() {} + +func NewT0() p0.T0 { + return S1{} +} + +func NewT1() T1 { + return S1{} +} diff --git a/test/fixedbugs/issue6295.dir/p2.go b/test/fixedbugs/issue6295.dir/p2.go new file mode 100644 index 000000000..4703ec035 --- /dev/null +++ b/test/fixedbugs/issue6295.dir/p2.go @@ -0,0 +1,19 @@ +// Copyright 2013 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 ( + "./p0" + "./p1" +) + +var ( + _ p0.T0 = p0.S0{} + _ p0.T0 = p1.S1{} + _ p0.T0 = p1.NewT0() + _ p0.T0 = p1.NewT1() // same as p1.S1{} +) + +func main() {} diff --git a/test/fixedbugs/issue6295.go b/test/fixedbugs/issue6295.go new file mode 100644 index 000000000..b8da21272 --- /dev/null +++ b/test/fixedbugs/issue6295.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2013 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. + +// Issue 6295: qualified name of unexported methods +// is corrupted during import. + +package ignored diff --git a/test/fixedbugs/issue6402.go b/test/fixedbugs/issue6402.go new file mode 100644 index 000000000..da5980c9a --- /dev/null +++ b/test/fixedbugs/issue6402.go @@ -0,0 +1,13 @@ +// errorcheck + +// 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. + +// Issue 6402: spurious 'use of untyped nil' error + +package p + +func f() uintptr { + return nil // ERROR "cannot use nil as type uintptr in return argument" +} diff --git a/test/fixedbugs/issue6403.go b/test/fixedbugs/issue6403.go new file mode 100644 index 000000000..b61e2e225 --- /dev/null +++ b/test/fixedbugs/issue6403.go @@ -0,0 +1,14 @@ +// errorcheck + +// 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. + +// Issue 6403: fix spurious 'const initializer is not a constant' error + +package p + +import "syscall" + +const A int = syscall.X // ERROR "undefined: syscall.X" +const B int = voidpkg.X // ERROR "undefined: voidpkg" diff --git a/test/fixedbugs/issue6405.go b/test/fixedbugs/issue6405.go new file mode 100644 index 000000000..b4551cc25 --- /dev/null +++ b/test/fixedbugs/issue6405.go @@ -0,0 +1,13 @@ +// errorcheck + +// 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. + +// Issue 6405: spurious 'not enough arguments to return' error + +package p + +func Open() (int, error) { + return OpenFile() // ERROR "undefined: OpenFile" +} diff --git a/test/fixedbugs/issue6406.go b/test/fixedbugs/issue6406.go new file mode 100644 index 000000000..5491193ef --- /dev/null +++ b/test/fixedbugs/issue6406.go @@ -0,0 +1,12 @@ +// errorcheck + +// 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. + +package main + +func main() { + s = "bob" // ERROR "undefined.*s" + _ = s // ERROR "undefined.*s" +} diff --git a/test/fixedbugs/issue6500.go b/test/fixedbugs/issue6500.go new file mode 100644 index 000000000..b265f9ae3 --- /dev/null +++ b/test/fixedbugs/issue6500.go @@ -0,0 +1,29 @@ +// errorcheck + +// 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. + +// Issue 6500: missing error when fallthrough appears in a block. + +package main + +func main() { + var x int + switch x { + case 0: + { + fallthrough // ERROR "fallthrough" + } + case 1: + { + switch x { + case 2: + fallthrough + case 3: + } + } + fallthrough + default: + } +} diff --git a/test/fixedbugs/issue6572.go b/test/fixedbugs/issue6572.go new file mode 100644 index 000000000..e75da54c9 --- /dev/null +++ b/test/fixedbugs/issue6572.go @@ -0,0 +1,21 @@ +// errorcheck + +// 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. + +package main + +func foo() (T, T) { // ERROR "undefined" + return 0, 0 +} + +func bar() (T, string, T) { // ERROR "undefined" + return 0, "", 0 +} + +func main() { + var x, y, z int + x, y = foo() + x, y, z = bar() // ERROR "cannot (use type|assign) string" +} diff --git a/test/fixedbugs/issue6789.dir/a.go b/test/fixedbugs/issue6789.dir/a.go new file mode 100644 index 000000000..9c90e0740 --- /dev/null +++ b/test/fixedbugs/issue6789.dir/a.go @@ -0,0 +1,14 @@ +// Copyright 2013 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 + +type unexported struct { + a int + b bool +} + +type Struct struct { + unexported +} diff --git a/test/fixedbugs/issue6789.dir/b.go b/test/fixedbugs/issue6789.dir/b.go new file mode 100644 index 000000000..b6a6fc317 --- /dev/null +++ b/test/fixedbugs/issue6789.dir/b.go @@ -0,0 +1,12 @@ +// Copyright 2013 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" + +type s a.Struct + +func main() { +} diff --git a/test/fixedbugs/issue6789.go b/test/fixedbugs/issue6789.go new file mode 100644 index 000000000..e3a2c3320 --- /dev/null +++ b/test/fixedbugs/issue6789.go @@ -0,0 +1,10 @@ +// rundir + +// Copyright 2013 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. + +// Issue 6789: gccgo failed to find the hash function for an +// unexported struct embedded in an exported struct. + +package ignored diff --git a/test/fixedbugs/issue6847.go b/test/fixedbugs/issue6847.go new file mode 100644 index 000000000..e6427e19a --- /dev/null +++ b/test/fixedbugs/issue6847.go @@ -0,0 +1,85 @@ +// 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. + +// Issue 6847: select clauses involving implicit conversion +// of channels trigger a spurious typechecking error during walk. + +package p + +type I1 interface { + String() +} +type I2 interface { + String() +} + +func F() { + var ( + cr <-chan int + cs chan<- int + c chan int + + ccr chan (<-chan int) + ccs chan chan<- int + cc chan chan int + + ok bool + ) + // Send cases. + select { + case ccr <- cr: + case ccr <- c: + } + select { + case ccs <- cs: + case ccs <- c: + } + select { + case ccr <- c: + default: + } + // Receive cases. + select { + case cr = <-cc: + case cs = <-cc: + case c = <-cc: + } + select { + case cr = <-cc: + default: + } + select { + case cr, ok = <-cc: + case cs, ok = <-cc: + case c = <-cc: + } + // Interfaces. + var ( + c1 chan I1 + c2 chan I2 + x1 I1 + x2 I2 + ) + select { + case c1 <- x1: + case c1 <- x2: + case c2 <- x1: + case c2 <- x2: + } + select { + case x1 = <-c1: + case x1 = <-c2: + case x2 = <-c1: + case x2 = <-c2: + } + select { + case x1, ok = <-c1: + case x1, ok = <-c2: + case x2, ok = <-c1: + case x2, ok = <-c2: + } + _ = ok +} diff --git a/test/fixedbugs/issue6889.go b/test/fixedbugs/issue6889.go new file mode 100644 index 000000000..46bb5dacf --- /dev/null +++ b/test/fixedbugs/issue6889.go @@ -0,0 +1,103 @@ +// errorcheck + +// 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. + +// Issue 6889: confusing error message: ovf in mpaddxx + +package main + +const ( + f1 = 1 + f2 = f1 * 2 + f3 = f2 * 3 + f4 = f3 * 4 + f5 = f4 * 5 + f6 = f5 * 6 + f7 = f6 * 7 + f8 = f7 * 8 + f9 = f8 * 9 + f10 = f9 * 10 + f11 = f10 * 11 + f12 = f11 * 12 + f13 = f12 * 13 + f14 = f13 * 14 + f15 = f14 * 15 + f16 = f15 * 16 + f17 = f16 * 17 + f18 = f17 * 18 + f19 = f18 * 19 + f20 = f19 * 20 + f21 = f20 * 21 + f22 = f21 * 22 + f23 = f22 * 23 + f24 = f23 * 24 + f25 = f24 * 25 + f26 = f25 * 26 + f27 = f26 * 27 + f28 = f27 * 28 + f29 = f28 * 29 + f30 = f29 * 30 + f31 = f30 * 31 + f32 = f31 * 32 + f33 = f32 * 33 + f34 = f33 * 34 + f35 = f34 * 35 + f36 = f35 * 36 + f37 = f36 * 37 + f38 = f37 * 38 + f39 = f38 * 39 + f40 = f39 * 40 + f41 = f40 * 41 + f42 = f41 * 42 + f43 = f42 * 43 + f44 = f43 * 44 + f45 = f44 * 45 + f46 = f45 * 46 + f47 = f46 * 47 + f48 = f47 * 48 + f49 = f48 * 49 + f50 = f49 * 50 + f51 = f50 * 51 + f52 = f51 * 52 + f53 = f52 * 53 + f54 = f53 * 54 + f55 = f54 * 55 + f56 = f55 * 56 + f57 = f56 * 57 + f58 = f57 * 58 + f59 = f58 * 59 + f60 = f59 * 60 + f61 = f60 * 61 + f62 = f61 * 62 + f63 = f62 * 63 + f64 = f63 * 64 + f65 = f64 * 65 + f66 = f65 * 66 + f67 = f66 * 67 + f68 = f67 * 68 + f69 = f68 * 69 + f70 = f69 * 70 + f71 = f70 * 71 + f72 = f71 * 72 + f73 = f72 * 73 + f74 = f73 * 74 + f75 = f74 * 75 + f76 = f75 * 76 + f77 = f76 * 77 + f78 = f77 * 78 + f79 = f78 * 79 + f80 = f79 * 80 + f81 = f80 * 81 + f82 = f81 * 82 + f83 = f82 * 83 + f84 = f83 * 84 + f85 = f84 * 85 + f86 = f85 * 86 + f87 = f86 * 87 + f88 = f87 * 88 + f89 = f88 * 89 + f90 = f89 * 90 + f91 = f90 * 91 // ERROR "overflow" +) diff --git a/test/fixedbugs/issue6899.go b/test/fixedbugs/issue6899.go new file mode 100644 index 000000000..a693bf285 --- /dev/null +++ b/test/fixedbugs/issue6899.go @@ -0,0 +1,13 @@ +// cmpout + +// Copyright 2013 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 "math" + +func main() { + println(math.Copysign(0, -1)) +} diff --git a/test/fixedbugs/issue6899.out b/test/fixedbugs/issue6899.out new file mode 100644 index 000000000..e2375f077 --- /dev/null +++ b/test/fixedbugs/issue6899.out @@ -0,0 +1 @@ +-0.000000e+000 diff --git a/test/fixedbugs/issue6902.go b/test/fixedbugs/issue6902.go new file mode 100644 index 000000000..5c2c545d2 --- /dev/null +++ b/test/fixedbugs/issue6902.go @@ -0,0 +1,21 @@ +// 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. + +// Issue 6902: confusing printing of large floating point constants + +package main + +import ( + "os" +) + +var x = -1e-10000 + +func main() { + if x != 0 { + os.Exit(1) + } +} diff --git a/test/fixedbugs/issue6964.go b/test/fixedbugs/issue6964.go new file mode 100644 index 000000000..821735c08 --- /dev/null +++ b/test/fixedbugs/issue6964.go @@ -0,0 +1,11 @@ +// errorcheck + +// Copyright 2013 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() { + _ = string(-4 + 2i + 2) // ERROR "-4\+2i" +} diff --git a/test/fixedbugs/issue7023.dir/a.go b/test/fixedbugs/issue7023.dir/a.go new file mode 100644 index 000000000..cdb543209 --- /dev/null +++ b/test/fixedbugs/issue7023.dir/a.go @@ -0,0 +1,10 @@ +// 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. + +package a + +func Foo() { + goto bar +bar: +} diff --git a/test/fixedbugs/issue7023.dir/b.go b/test/fixedbugs/issue7023.dir/b.go new file mode 100644 index 000000000..c6fe40dfa --- /dev/null +++ b/test/fixedbugs/issue7023.dir/b.go @@ -0,0 +1,11 @@ +// 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. + +package b + +import ( + "./a" +) + +var f = a.Foo diff --git a/test/fixedbugs/issue7023.go b/test/fixedbugs/issue7023.go new file mode 100644 index 000000000..f18c6113e --- /dev/null +++ b/test/fixedbugs/issue7023.go @@ -0,0 +1,10 @@ +// compiledir + +// 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. + +// Issue 7023: corrupted export data when an inlined function +// contains a goto. + +package ignored diff --git a/test/fixedbugs/issue7044.go b/test/fixedbugs/issue7044.go new file mode 100644 index 000000000..cac6a7683 --- /dev/null +++ b/test/fixedbugs/issue7044.go @@ -0,0 +1,43 @@ +// 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. + +// Issue 7044: bad AMOVFD and AMOVDF assembly generation on +// arm for registers above 7. + +package main + +import ( + "fmt" + "reflect" +) + +func f() [16]float32 { + f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15 := + float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1), float32(1) + // Use all 16 registers to do float32 --> float64 conversion. + d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15 := + float64(f0), float64(f1), float64(f2), float64(f3), float64(f4), float64(f5), float64(f6), float64(f7), float64(f8), float64(f9), float64(f10), float64(f11), float64(f12), float64(f13), float64(f14), float64(f15) + // Use all 16 registers to do float64 --> float32 conversion. + g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15 := + float32(d0), float32(d1), float32(d2), float32(d3), float32(d4), float32(d5), float32(d6), float32(d7), float32(d8), float32(d9), float32(d10), float32(d11), float32(d12), float32(d13), float32(d14), float32(d15) + // Force another conversion, so that the previous conversion doesn't + // get optimized away into constructing the returned array. With current + // optimizations, constructing the returned array uses only + // a single register. + e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15 := + float64(g0), float64(g1), float64(g2), float64(g3), float64(g4), float64(g5), float64(g6), float64(g7), float64(g8), float64(g9), float64(g10), float64(g11), float64(g12), float64(g13), float64(g14), float64(g15) + return [16]float32{ + float32(e0), float32(e1), float32(e2), float32(e3), float32(e4), float32(e5), float32(e6), float32(e7), float32(e8), float32(e9), float32(e10), float32(e11), float32(e12), float32(e13), float32(e14), float32(e15), + } +} + +func main() { + want := [16]float32{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} + got := f() + if !reflect.DeepEqual(got, want) { + fmt.Printf("f() = %#v; want %#v\n", got, want) + } +} diff --git a/test/fixedbugs/issue7050.go b/test/fixedbugs/issue7050.go new file mode 100644 index 000000000..e58b68404 --- /dev/null +++ b/test/fixedbugs/issue7050.go @@ -0,0 +1,19 @@ +// 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. + +package main + +import ( + "fmt" + "os" +) + +func main() { + _, err := os.Stdout.Write(nil) + if err != nil { + fmt.Printf("BUG: os.Stdout.Write(nil) = %v\n", err) + } +} diff --git a/test/fixedbugs/issue7083.go b/test/fixedbugs/issue7083.go new file mode 100644 index 000000000..79bfd3b5e --- /dev/null +++ b/test/fixedbugs/issue7083.go @@ -0,0 +1,22 @@ +// run + +package main + +import "runtime/debug" + +func f(m map[int]*string, i int) { + s := "" + m[i] = &s +} + +func main() { + debug.SetGCPercent(0) + m := map[int]*string{} + for i := 0; i < 40; i++ { + f(m, i) + if len(*m[i]) != 0 { + println("bad length", i, m[i], len(*m[i])) + panic("bad length") + } + } +} diff --git a/test/fixedbugs/issue7129.go b/test/fixedbugs/issue7129.go new file mode 100644 index 000000000..2425cbd34 --- /dev/null +++ b/test/fixedbugs/issue7129.go @@ -0,0 +1,21 @@ +// errorcheck + +// 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. + +// Issue 7129: inconsistent "wrong arg type" error for multivalued g in f(g()) + +package main + +func f(int) {} + +func g() bool { return true } + +func h(int, int) {} + +func main() { + f(g()) // ERROR "in argument to f" + f(true) // ERROR "in argument to f" + h(true, true) // ERROR "in argument to h" +} diff --git a/test/fixedbugs/issue7150.go b/test/fixedbugs/issue7150.go new file mode 100644 index 000000000..264958a08 --- /dev/null +++ b/test/fixedbugs/issue7150.go @@ -0,0 +1,17 @@ +// errorcheck + +// 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. + +// issue 7150: array index out of bounds error off by one + +package main + +func main() { + _ = [0]int{-1: 50} // ERROR "array index must be non-negative integer constant" + _ = [0]int{0: 0} // ERROR "array index 0 out of bounds \[0:0\]" + _ = [0]int{5: 25} // ERROR "array index 5 out of bounds \[0:0\]" + _ = [10]int{2: 10, 15: 30} // ERROR "array index 15 out of bounds \[0:10\]" + _ = [10]int{5: 5, 1: 1, 12: 12} // ERROR "array index 12 out of bounds \[0:10\]" +} diff --git a/test/fixedbugs/issue7153.go b/test/fixedbugs/issue7153.go new file mode 100644 index 000000000..d70d8582a --- /dev/null +++ b/test/fixedbugs/issue7153.go @@ -0,0 +1,11 @@ +// errorcheck + +// 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. + +// Issue 7153: array invalid index error duplicated on successive bad values + +package p + +var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type bool\) as type int in array element" diff --git a/test/fixedbugs/issue7214.go b/test/fixedbugs/issue7214.go new file mode 100644 index 000000000..82ddf74c3 --- /dev/null +++ b/test/fixedbugs/issue7214.go @@ -0,0 +1,30 @@ +// errorcheck + +// 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. + +// Issue 7214: No duplicate key error for maps with interface{} key type + +package p + +var _ = map[interface{}]int{2: 1, 2: 1} // ERROR "duplicate key" +var _ = map[interface{}]int{int(2): 1, int16(2): 1} +var _ = map[interface{}]int{int16(2): 1, int16(2): 1} // ERROR "duplicate key" + +type S string + +var _ = map[interface{}]int{"a": 1, "a": 1} // ERROR "duplicate key" +var _ = map[interface{}]int{"a": 1, S("a"): 1} +var _ = map[interface{}]int{S("a"): 1, S("a"): 1} // ERROR "duplicate key" + +type I interface { + f() +} + +type N int + +func (N) f() {} + +var _ = map[I]int{N(0): 1, N(2): 1} +var _ = map[I]int{N(2): 1, N(2): 1} // ERROR "duplicate key" diff --git a/test/fixedbugs/issue7223.go b/test/fixedbugs/issue7223.go new file mode 100644 index 000000000..c5955d599 --- /dev/null +++ b/test/fixedbugs/issue7223.go @@ -0,0 +1,20 @@ +// errorcheck + +// 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. + +package main + +var bits1 uint = 10 +const bits2 uint = 10 + +func main() { + _ = make([]byte, 1<<bits1) + _ = make([]byte, 1<<bits2) + _ = make([]byte, nil) // ERROR "non-integer.*len" + _ = make([]byte, nil, 2) // ERROR "non-integer.*len" + _ = make([]byte, 1, nil) // ERROR "non-integer.*cap" + _ = make([]byte, true) // ERROR "non-integer.*len" + _ = make([]byte, "abc") // ERROR "non-integer.*len" +} diff --git a/test/fixedbugs/issue7272.go b/test/fixedbugs/issue7272.go new file mode 100644 index 000000000..97a08da09 --- /dev/null +++ b/test/fixedbugs/issue7272.go @@ -0,0 +1,48 @@ +// 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. + +// Issue 7272: test builtin functions in statement context and in +// go/defer functions. + +package p + +func F() { + var a []int + var c chan int + var m map[int]int + + close(c) + copy(a, a) + delete(m, 0) + panic(0) + print("foo") + println("bar") + recover() + + (close(c)) + (copy(a, a)) + (delete(m, 0)) + (panic(0)) + (print("foo")) + (println("bar")) + (recover()) + + go close(c) + go copy(a, a) + go delete(m, 0) + go panic(0) + go print("foo") + go println("bar") + go recover() + + defer close(c) + defer copy(a, a) + defer delete(m, 0) + defer panic(0) + defer print("foo") + defer println("bar") + defer recover() +} diff --git a/test/fixedbugs/issue7310.go b/test/fixedbugs/issue7310.go new file mode 100644 index 000000000..4a535a1fc --- /dev/null +++ b/test/fixedbugs/issue7310.go @@ -0,0 +1,15 @@ +// errorcheck + +// 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. + +// Internal compiler crash used to stop errors during second copy. + +package main + +func main() { + _ = copy(nil, []int{}) // ERROR "use of untyped nil" + _ = copy([]int{}, nil) // ERROR "use of untyped nil" + _ = 1+true // ERROR "cannot convert true" "mismatched types int and bool" +} diff --git a/test/fixedbugs/issue7316.go b/test/fixedbugs/issue7316.go new file mode 100644 index 000000000..4b32261d4 --- /dev/null +++ b/test/fixedbugs/issue7316.go @@ -0,0 +1,37 @@ +// runoutput + +// 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. + +// Issue 7316 +// This test exercises all types of numeric conversions, which was one +// of the sources of etype mismatch during register allocation in 8g. + +package main + +import "fmt" + +const tpl = ` +func init() { + var i %s + j := %s(i) + _ = %s(j) +} +` + +func main() { + fmt.Println("package main") + ntypes := []string{ + "byte", "rune", "uintptr", + "float32", "float64", + "int", "int8", "int16", "int32", "int64", + "uint", "uint8", "uint16", "uint32", "uint64", + } + for i, from := range ntypes { + for _, to := range ntypes[i:] { + fmt.Printf(tpl, from, to, from) + } + } + fmt.Println("func main() {}") +} diff --git a/test/fixedbugs/issue7346.go b/test/fixedbugs/issue7346.go new file mode 100644 index 000000000..dd5ea222f --- /dev/null +++ b/test/fixedbugs/issue7346.go @@ -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. + +// issue 7346 : internal error "doasm" error due to checknil +// of a nil literal. + +package main + +func main() { + _ = *(*int)(nil) +} diff --git a/test/fixedbugs/issue7366.go b/test/fixedbugs/issue7366.go new file mode 100644 index 000000000..754da6fa2 --- /dev/null +++ b/test/fixedbugs/issue7366.go @@ -0,0 +1,21 @@ +// 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. + +// issue 7366: generates a temporary with ideal type +// during comparison of small structs. + +package main + +type T struct { + data [10]byte +} + +func main() { + var a T + var b T + if a == b { + } +} diff --git a/test/fixedbugs/issue7405.go b/test/fixedbugs/issue7405.go new file mode 100644 index 000000000..52e1176c1 --- /dev/null +++ b/test/fixedbugs/issue7405.go @@ -0,0 +1,51 @@ +// 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. + +// Issue 7405: the equality function for struct with many +// embedded fields became more complex after fixing issue 7366, +// leading to out of registers on 386. + +package p + +type T1 struct { + T2 + T3 + T4 +} + +type T2 struct { + Conn +} + +type T3 struct { + PacketConn +} + +type T4 struct { + PacketConn + T5 +} + +type T5 struct { + x int + T6 +} + +type T6 struct { + y, z int +} + +type Conn interface { + A() +} + +type PacketConn interface { + B() +} + +func F(a, b T1) bool { + return a == b +} diff --git a/test/fixedbugs/issue7419.go b/test/fixedbugs/issue7419.go new file mode 100644 index 000000000..39b454c05 --- /dev/null +++ b/test/fixedbugs/issue7419.go @@ -0,0 +1,25 @@ +// 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. + +// Issue 7419: odd behavior for float constants underflowing to 0 + +package main + +import ( + "os" +) + +var x = 1e-779137 +var y = 1e-779138 + +func main() { + if x != 0 { + os.Exit(1) + } + if y != 0 { + os.Exit(2) + } +} diff --git a/test/fixedbugs/issue7525.go b/test/fixedbugs/issue7525.go new file mode 100644 index 000000000..4e1d88aab --- /dev/null +++ b/test/fixedbugs/issue7525.go @@ -0,0 +1,19 @@ +// errorcheck + +// 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. + +// Issue 7525: self-referential array types. + +package main + +import "unsafe" + +var x struct { + a [unsafe.Sizeof(x.a)]int // ERROR "array bound|typechecking loop|invalid expression" + b [unsafe.Offsetof(x.b)]int // ERROR "array bound" + c [unsafe.Alignof(x.c)]int // ERROR "array bound|invalid expression" + d [len(x.d)]int // ERROR "array bound|invalid array" + e [cap(x.e)]int // ERROR "array bound|invalid array" +} diff --git a/test/fixedbugs/issue7538a.go b/test/fixedbugs/issue7538a.go new file mode 100644 index 000000000..283d9eb1b --- /dev/null +++ b/test/fixedbugs/issue7538a.go @@ -0,0 +1,15 @@ +// errorcheck + +// 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. + +// Issue 7538: blank (_) labels handled incorrectly + +package p + +func f() { +_: +_: + goto _ // ERROR "not defined" +} diff --git a/test/fixedbugs/issue7538b.go b/test/fixedbugs/issue7538b.go new file mode 100644 index 000000000..28cef5d60 --- /dev/null +++ b/test/fixedbugs/issue7538b.go @@ -0,0 +1,13 @@ +// 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. + +// Issue 7538: blank (_) labels handled incorrectly + +package p + +func f() { +_: +} diff --git a/test/fixedbugs/issue7547.go b/test/fixedbugs/issue7547.go new file mode 100644 index 000000000..f75a33036 --- /dev/null +++ b/test/fixedbugs/issue7547.go @@ -0,0 +1,17 @@ +// 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. + +package main + +func f() map[string]interface{} { + var p *map[string]map[string]interface{} + _ = p + return nil +} + +func main() { + f() +} diff --git a/test/fixedbugs/issue7550.go b/test/fixedbugs/issue7550.go new file mode 100644 index 000000000..0c4cf9307 --- /dev/null +++ b/test/fixedbugs/issue7550.go @@ -0,0 +1,27 @@ +// 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. + +package main + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("not panicking") + } + }() + f() +} + +func f() { + length := int(^uint(0) >> 1) + a := make([]struct{}, length) + b := make([]struct{}, length) + _ = append(a, b...) +} + +func main() { + shouldPanic(f) +} diff --git a/test/fixedbugs/issue7590.go b/test/fixedbugs/issue7590.go new file mode 100644 index 000000000..e283832c3 --- /dev/null +++ b/test/fixedbugs/issue7590.go @@ -0,0 +1,21 @@ +// 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. + +// Issue 7590: gccgo incorrectly traverses nested composite literals. + +package p + +type S struct { + F int +} + +var M = map[string]S{ + "a": { F: 1 }, +} + +var P = M["a"] + +var F = P.F diff --git a/test/fixedbugs/issue7648.dir/a.go b/test/fixedbugs/issue7648.dir/a.go new file mode 100644 index 000000000..c76aaa675 --- /dev/null +++ b/test/fixedbugs/issue7648.dir/a.go @@ -0,0 +1,11 @@ +// 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. + +package a + +const ( + sinPi4 = 0.70710678118654752440084436210484903928483593768847 + A = complex(sinPi4, -sinPi4) +) + diff --git a/test/fixedbugs/issue7648.dir/b.go b/test/fixedbugs/issue7648.dir/b.go new file mode 100644 index 000000000..b9223ed4e --- /dev/null +++ b/test/fixedbugs/issue7648.dir/b.go @@ -0,0 +1,11 @@ +// 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. + +package b + +import "a" + +func f() { + println(a.A) +} diff --git a/test/fixedbugs/issue7648.go b/test/fixedbugs/issue7648.go new file mode 100644 index 000000000..b391c4a31 --- /dev/null +++ b/test/fixedbugs/issue7648.go @@ -0,0 +1,9 @@ +// compiledir + +// 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. + +// Issue 7648: spurious "bad negated constant" for complex constants. + +package ignored diff --git a/test/fixedbugs/issue7675.go b/test/fixedbugs/issue7675.go new file mode 100644 index 000000000..d97ee357a --- /dev/null +++ b/test/fixedbugs/issue7675.go @@ -0,0 +1,24 @@ +// errorcheck + +// 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. + +// Issue 7675: fewer errors for wrong argument count + +package p + +func f(string, int, float64, string) + +func g(string, int, float64, ...string) + +func main() { + f(1, 0.5, "hello") // ERROR "not enough arguments" + f("1", 2, 3.1, "4") + f(1, 0.5, "hello", 4, 5) // ERROR "too many arguments" + g(1, 0.5) // ERROR "not enough arguments" + g("1", 2, 3.1) + g(1, 0.5, []int{3, 4}...) // ERROR "not enough arguments" + g("1", 2, 3.1, "4", "5") + g(1, 0.5, "hello", 4, []int{5, 6}...) // ERROR "too many arguments" +} diff --git a/test/fixedbugs/issue7742.go b/test/fixedbugs/issue7742.go new file mode 100644 index 000000000..dc167c22e --- /dev/null +++ b/test/fixedbugs/issue7742.go @@ -0,0 +1,18 @@ +// 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. + +// Issue 7742: cannot use &autotmp_0001 (type *map[string]string) as type *string in function argument + +package main + +var ( + m map[string]string + v string +) + +func main() { + m[v], _ = v, v +} diff --git a/test/fixedbugs/issue7794.go b/test/fixedbugs/issue7794.go new file mode 100644 index 000000000..1e303bd4f --- /dev/null +++ b/test/fixedbugs/issue7794.go @@ -0,0 +1,12 @@ +// 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. + +package main + +func main() { + var a [10]int + const ca = len(a) +} diff --git a/test/fixedbugs/issue7863.go b/test/fixedbugs/issue7863.go new file mode 100644 index 000000000..97f225535 --- /dev/null +++ b/test/fixedbugs/issue7863.go @@ -0,0 +1,60 @@ +// 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. + +package main + +import ( + "fmt" +) + +type Foo int64 + +func (f *Foo) F() int64 { + return int64(*f) +} + +type Bar int64 + +func (b Bar) F() int64 { + return int64(b) +} + +type Baz int32 + +func (b Baz) F() int64 { + return int64(b) +} + +func main() { + foo := Foo(123) + f := foo.F + if foo.F() != f() { + bug() + fmt.Println("foo.F", foo.F(), f()) + } + bar := Bar(123) + f = bar.F + if bar.F() != f() { + bug() + fmt.Println("bar.F", bar.F(), f()) // duh! + } + + baz := Baz(123) + f = baz.F + if baz.F() != f() { + bug() + fmt.Println("baz.F", baz.F(), f()) + } +} + +var bugged bool + +func bug() { + if !bugged { + bugged = true + fmt.Println("BUG") + } +} diff --git a/test/fixedbugs/issue7867.go b/test/fixedbugs/issue7867.go new file mode 100644 index 000000000..9f28a7144 --- /dev/null +++ b/test/fixedbugs/issue7867.go @@ -0,0 +1,43 @@ +// runoutput + +// 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. + +// Issue 7867. + +package main + +import "fmt" + +const tpl = ` +func Test%d(t %s) { + _ = t + _ = t +} +` + +func main() { + fmt.Println("package main") + types := []string{ + // These types always passed + "bool", "int", "rune", + "*int", "uintptr", + "float32", "float64", + "chan struct{}", + "map[string]struct{}", + "func()", "func(string)error", + + // These types caused compilation failures + "complex64", "complex128", + "struct{}", "struct{n int}", "struct{e error}", "struct{m map[string]string}", + "string", + "[4]byte", + "[]byte", + "interface{}", "error", + } + for i, typ := range types { + fmt.Printf(tpl, i, typ) + } + fmt.Println("func main() {}") +} diff --git a/test/fixedbugs/issue7884.go b/test/fixedbugs/issue7884.go new file mode 100644 index 000000000..497e26113 --- /dev/null +++ b/test/fixedbugs/issue7884.go @@ -0,0 +1,15 @@ +// 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. + +package main + +import "fmt" + +func main() { + var ii interface{} = 5 + zz, err := ii.(interface{}) + fmt.Println(zz, err) +} diff --git a/test/fixedbugs/issue7944.go b/test/fixedbugs/issue7944.go new file mode 100644 index 000000000..9e5bed1a1 --- /dev/null +++ b/test/fixedbugs/issue7944.go @@ -0,0 +1,40 @@ +// 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. + +// Issue 7944: +// Liveness bitmaps said b was live at call to g, +// but no one told the register optimizer. + +package main + +import "runtime" + +func f(b []byte) { + for len(b) > 0 { + n := len(b) + n = f1(n) + f2(b[n:]) + b = b[n:] + } + g() +} + +func f1(n int) int { + runtime.GC() + return n +} + +func f2(b []byte) { + runtime.GC() +} + +func g() { + runtime.GC() +} + +func main() { + f(make([]byte, 100)) +} diff --git a/test/fixedbugs/issue7995.go b/test/fixedbugs/issue7995.go new file mode 100644 index 000000000..05f116823 --- /dev/null +++ b/test/fixedbugs/issue7995.go @@ -0,0 +1,25 @@ +// 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. + +// Issue 7995: globals not flushed quickly enough. + +package main + +import "fmt" + +var ( + p = 1 + q = &p +) + +func main() { + p = 50 + *q = 100 + s := fmt.Sprintln(p, *q) + if s != "100 100\n" { + println("BUG:", s) + } +} diff --git a/test/fixedbugs/issue7995b.dir/x1.go b/test/fixedbugs/issue7995b.dir/x1.go new file mode 100644 index 000000000..075911b92 --- /dev/null +++ b/test/fixedbugs/issue7995b.dir/x1.go @@ -0,0 +1,16 @@ +package x1 + +import "fmt" + +var P int + +var b bool + +func F(x *int) string { + if b { // avoid inlining + F(x) + } + P = 50 + *x = 100 + return fmt.Sprintln(P, *x) +} diff --git a/test/fixedbugs/issue7995b.dir/x2.go b/test/fixedbugs/issue7995b.dir/x2.go new file mode 100644 index 000000000..eea23eabb --- /dev/null +++ b/test/fixedbugs/issue7995b.dir/x2.go @@ -0,0 +1,10 @@ +package main + +import "./x1" + +func main() { + s := x1.F(&x1.P) + if s != "100 100\n" { + println("BUG:", s) + } +} diff --git a/test/fixedbugs/issue7995b.go b/test/fixedbugs/issue7995b.go new file mode 100644 index 000000000..2f57371e3 --- /dev/null +++ b/test/fixedbugs/issue7995b.go @@ -0,0 +1,9 @@ +// rundir + +// 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. + +// Issue 7995: globals not flushed quickly enough. + +package ignored diff --git a/test/fixedbugs/issue7996.go b/test/fixedbugs/issue7996.go new file mode 100644 index 000000000..98289eb0c --- /dev/null +++ b/test/fixedbugs/issue7996.go @@ -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. + +// /tmp/x.go:5: illegal constant expression: bool == interface {} + +package p + +var m = map[interface{}]struct{}{ + nil: {}, + true: {}, +} diff --git a/test/fixedbugs/issue7997.go b/test/fixedbugs/issue7997.go new file mode 100644 index 000000000..10c526273 --- /dev/null +++ b/test/fixedbugs/issue7997.go @@ -0,0 +1,53 @@ +// 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. + +// /tmp/x.go:3: internal error: f &p (type *int) recorded as live on entry + +package p + +func f(ch chan int) *int { + select { + case p1x := <-ch: + return &p1x + default: + // ok + } + select { + case p1 := <-ch: + return &p1 + default: + // ok + } + select { + case p2 := <-ch: + return &p2 + case p3 := <-ch: + return &p3 + default: + // ok + } + select { + case p4, ok := <-ch: + if ok { + return &p4 + } + default: + // ok + } + select { + case p5, ok := <-ch: + if ok { + return &p5 + } + case p6, ok := <-ch: + if !ok { + return &p6 + } + default: + // ok + } + return nil +} diff --git a/test/fixedbugs/issue7998.go b/test/fixedbugs/issue7998.go new file mode 100644 index 000000000..245035ede --- /dev/null +++ b/test/fixedbugs/issue7998.go @@ -0,0 +1,23 @@ +// 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. + +// /tmp/x.go:5: cannot use _ as value + +package p + +func f(ch chan int) bool { + select { + case _, ok := <-ch: + return ok + } + _, ok := <-ch + _ = ok + select { + case _, _ = <-ch: + return true + } + return false +} diff --git a/test/fixedbugs/issue8004.go b/test/fixedbugs/issue8004.go new file mode 100644 index 000000000..37e2fe066 --- /dev/null +++ b/test/fixedbugs/issue8004.go @@ -0,0 +1,59 @@ +// 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. + +package main + +import ( + "reflect" + "runtime" + "unsafe" +) + +func main() { + test1() + test2() +} + +func test1() { + var all []interface{} + for i := 0; i < 100; i++ { + p := new([]int) + *p = append(*p, 1, 2, 3, 4) + h := (*reflect.SliceHeader)(unsafe.Pointer(p)) + all = append(all, h, p) + } + runtime.GC() + for i := 0; i < 100; i++ { + p := *all[2*i+1].(*[]int) + if p[0] != 1 || p[1] != 2 || p[2] != 3 || p[3] != 4 { + println("BUG test1: bad slice at index", i, p[0], p[1], p[2], p[3]) + return + } + } +} + +type T struct { + H *reflect.SliceHeader + P *[]int +} + +func test2() { + var all []T + for i := 0; i < 100; i++ { + p := new([]int) + *p = append(*p, 1, 2, 3, 4) + h := (*reflect.SliceHeader)(unsafe.Pointer(p)) + all = append(all, T{H: h}, T{P: p}) + } + runtime.GC() + for i := 0; i < 100; i++ { + p := *all[2*i+1].P + if p[0] != 1 || p[1] != 2 || p[2] != 3 || p[3] != 4 { + println("BUG test2: bad slice at index", i, p[0], p[1], p[2], p[3]) + return + } + } +} diff --git a/test/fixedbugs/issue8011.go b/test/fixedbugs/issue8011.go new file mode 100644 index 000000000..b966174c0 --- /dev/null +++ b/test/fixedbugs/issue8011.go @@ -0,0 +1,18 @@ +// 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. + +package main + +func main() { + c := make(chan chan int, 1) + c1 := make(chan int, 1) + c1 <- 42 + c <- c1 + x := <-<-c + if x != 42 { + println("BUG:", x, "!= 42") + } +} diff --git a/test/fixedbugs/issue8028.go b/test/fixedbugs/issue8028.go new file mode 100644 index 000000000..7ceb902d4 --- /dev/null +++ b/test/fixedbugs/issue8028.go @@ -0,0 +1,27 @@ +// 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. + +// Issue 8028. Used to fail in -race mode with "non-orig name" error. + +package p + +var ( + t2 = T{F, "s1"} + t1 = T{F, "s2"} + + tt = [...]T{t1, t2} +) + +type I interface{} + +type T struct { + F func() I + S string +} + +type E struct{} + +func F() I { return new(E) } diff --git a/test/fixedbugs/issue8036.go b/test/fixedbugs/issue8036.go new file mode 100644 index 000000000..f32fde84a --- /dev/null +++ b/test/fixedbugs/issue8036.go @@ -0,0 +1,45 @@ +// 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. + +// Issue 8036. Stores necessary for stack scan being eliminated as redundant by optimizer. + +package main + +import "runtime" + +type T struct { + X *int + Y *int + Z *int +} + +type TI [3]uintptr + +func G() (t TI) { + t[0] = 1 + t[1] = 2 + t[2] = 3 + runtime.GC() // prevent inlining + return +} + +func F() (t T) { + t.X = newint() + t.Y = t.X + t.Z = t.Y + runtime.GC() // prevent inlining + return +} + +func newint() *int { + runtime.GC() + return nil +} + +func main() { + G() // leave non-pointers where F's return values go + F() +} diff --git a/test/fixedbugs/issue8039.go b/test/fixedbugs/issue8039.go new file mode 100644 index 000000000..b13e474d9 --- /dev/null +++ b/test/fixedbugs/issue8039.go @@ -0,0 +1,23 @@ +// 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. + +// issue 8039. defer copy(x, <-c) did not rewrite <-c properly. + +package main + +func f(s []int) { + c := make(chan []int, 1) + c <- []int{1} + defer copy(s, <-c) +} + +func main() { + x := make([]int, 1) + f(x) + if x[0] != 1 { + println("BUG", x[0]) + } +} diff --git a/test/fixedbugs/issue8047.go b/test/fixedbugs/issue8047.go new file mode 100644 index 000000000..fe7ada5c0 --- /dev/null +++ b/test/fixedbugs/issue8047.go @@ -0,0 +1,29 @@ +// 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. + +// Issue 8047. Stack copier shouldn't crash if there +// is a nil defer. + +package main + +func stackit(n int) { + if n == 0 { + return + } + stackit(n - 1) +} + +func main() { + defer func() { + // catch & ignore panic from nil defer below + err := recover() + if err == nil { + panic("defer of nil func didn't panic") + } + }() + defer ((func())(nil))() + stackit(1000) +} diff --git a/test/fixedbugs/issue8047b.go b/test/fixedbugs/issue8047b.go new file mode 100644 index 000000000..de6acaab5 --- /dev/null +++ b/test/fixedbugs/issue8047b.go @@ -0,0 +1,22 @@ +// 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. + +// Issue 8047. Defer setup during panic shouldn't crash for nil defer. + +package main + +func main() { + defer func() { + recover() + }() + f() +} + +func f() { + var g func() + defer g() + panic(1) +} diff --git a/test/fixedbugs/issue8048.go b/test/fixedbugs/issue8048.go new file mode 100644 index 000000000..a7984c45a --- /dev/null +++ b/test/fixedbugs/issue8048.go @@ -0,0 +1,107 @@ +// 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. + +// Issue 8048. Incorrect handling of liveness when walking stack +// containing faulting frame. + +package main + +import "runtime" + +func main() { + test1() + test2() + test3() +} + +func test1() { + // test1f will panic without its own defer. + // The runtime.GC checks that we can walk the stack + // at that point and not get confused. + // The recover lets test1 exit normally. + defer func() { + runtime.GC() + recover() + }() + test1f() +} + +func test1f() { + // Because b == false, the if does not execute, + // so x == nil, so the println(*x) faults reading + // from nil. The compiler will lay out the code + // so that the if body occurs above the *x, + // so if the liveness info at the *x is used, it will + // find the liveness at the call to runtime.GC. + // It will think y is live, but y is uninitialized, + // and the runtime will crash detecting a bad slice. + // The runtime should see that there are no defers + // corresponding to this panicked frame and ignore + // the frame entirely. + var x *int + var b bool + if b { + y := make([]int, 1) + runtime.GC() + x = &y[0] + } + println(*x) +} + +func test2() { + // Same as test1, but the fault happens in the function with the defer. + // The runtime should see the defer and garbage collect the frame + // as if the PC were immediately after the defer statement. + defer func() { + runtime.GC() + recover() + }() + var x *int + var b bool + if b { + y := make([]int, 1) + runtime.GC() + x = &y[0] + } + println(*x) +} + +func test3() { + // Like test1 but avoid array index, which does not + // move to end of function on ARM. + defer func() { + runtime.GC() + recover() + }() + test3setup() + test3f() +} + +func test3setup() { + var x uintptr + var b bool + b = true + if b { + y := uintptr(123) + runtime.GC() + x = y + } + runtime.GC() + globl = x +} + +var globl uintptr + +func test3f() { + var x *int + var b bool + if b { + y := new(int) + runtime.GC() + x = y + } + println(*x) +} diff --git a/test/fixedbugs/issue8073.go b/test/fixedbugs/issue8073.go new file mode 100644 index 000000000..660122110 --- /dev/null +++ b/test/fixedbugs/issue8073.go @@ -0,0 +1,15 @@ +// 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. + +// issue 8073. +// was "internal compiler error: overflow: float64 integer constant" + +package main + +func main() { + var x int + _ = float64(x * 0) +} diff --git a/test/fixedbugs/issue8076.go b/test/fixedbugs/issue8076.go new file mode 100644 index 000000000..ad8906775 --- /dev/null +++ b/test/fixedbugs/issue8076.go @@ -0,0 +1,17 @@ +// 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. + +// Issue 8076. nilwalkfwd walked forward forever +// on the instruction loop following the dereference. + +package main + +func main() { + _ = *(*int)(nil) +L: + _ = 0 + goto L +} diff --git a/test/fixedbugs/issue8132.go b/test/fixedbugs/issue8132.go new file mode 100644 index 000000000..52f5d39c2 --- /dev/null +++ b/test/fixedbugs/issue8132.go @@ -0,0 +1,32 @@ +// 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. + +// issue 8132. stack walk handling of panic stack was confused +// about what was legal. + +package main + +import "runtime" + +var p *int + +func main() { + func() { + defer func() { + runtime.GC() + recover() + }() + var x [8192]byte + func(x [8192]byte) { + defer func() { + if err := recover(); err != nil { + println(*p) + } + }() + println(*p) + }(x) + }() +} diff --git a/test/fixedbugs/issue8139.go b/test/fixedbugs/issue8139.go new file mode 100644 index 000000000..821c9ff65 --- /dev/null +++ b/test/fixedbugs/issue8139.go @@ -0,0 +1,50 @@ +// 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. + +// Issue 8139. The x.(T) assertions used to write 1 (unexpected) +// return byte for the 0-byte return value T. + +package main + +import "fmt" + +type T struct{} + +func (T) M() {} + +type M interface { + M() +} + +var e interface{} = T{} +var i M = T{} +var b bool + +func f1() int { + if b { + return f1() // convince inliner not to inline + } + z := 0x11223344 + _ = e.(T) + return z +} + +func f2() int { + if b { + return f1() // convince inliner not to inline + } + z := 0x11223344 + _ = i.(T) + return z +} + +func main() { + x := f1() + y := f2() + if x != 0x11223344 || y != 0x11223344 { + fmt.Printf("BUG: x=%#x y=%#x, want 0x11223344 for both\n", x, y) + } +} diff --git a/test/fixedbugs/issue8155.go b/test/fixedbugs/issue8155.go new file mode 100644 index 000000000..c611f6cb1 --- /dev/null +++ b/test/fixedbugs/issue8155.go @@ -0,0 +1,48 @@ +// 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. + +// Issue 8155. +// Alignment of stack prologue zeroing was wrong on 64-bit Native Client +// (because of 32-bit pointers). + +package main + +import "runtime" + +func bad(b bool) uintptr { + var p **int + var x1 uintptr + x1 = 1 + if b { + var x [11]*int + p = &x[0] + } + if b { + var x [1]*int + p = &x[0] + } + runtime.GC() + if p != nil { + x1 = uintptr(**p) + } + return x1 +} + +func poison() uintptr { + runtime.GC() + var x [20]uintptr + var s uintptr + for i := range x { + x[i] = uintptr(i+1) + s += x[i] + } + return s +} + +func main() { + poison() + bad(false) +} diff --git a/test/fixedbugs/issue8158.go b/test/fixedbugs/issue8158.go new file mode 100644 index 000000000..b110de11f --- /dev/null +++ b/test/fixedbugs/issue8158.go @@ -0,0 +1,41 @@ +// 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. + +package main + +import ( + "runtime" + "time" +) + +func main() { + c := make(chan bool, 1) + go f1(c) + <-c + time.Sleep(10 * time.Millisecond) + go f2(c) + <-c +} + +func f1(done chan bool) { + defer func() { + recover() + done <- true + runtime.Goexit() // left stack-allocated Panic struct on gp->panic stack + }() + panic("p") +} + +func f2(done chan bool) { + defer func() { + recover() + done <- true + runtime.Goexit() + }() + time.Sleep(10 * time.Millisecond) // overwrote Panic struct with Timer struct + runtime.GC() // walked gp->panic list, found mangled Panic struct, crashed + panic("p") +} |