diff options
Diffstat (limited to 'test/fixedbugs')
64 files changed, 1353 insertions, 21 deletions
diff --git a/test/fixedbugs/bug173.go b/test/fixedbugs/bug173.go index 6479bb253..3515c649b 100644 --- a/test/fixedbugs/bug173.go +++ b/test/fixedbugs/bug173.go @@ -18,4 +18,6 @@ func main() { } for _ = range t { } + for range t { + } } diff --git a/test/fixedbugs/bug255.go b/test/fixedbugs/bug255.go index acf4f2391..65ed1b8f6 100644 --- a/test/fixedbugs/bug255.go +++ b/test/fixedbugs/bug255.go @@ -6,10 +6,15 @@ package main -var a [10]int // ok -var b [1e1]int // ok -var c [1.5]int // ERROR "truncated" -var d ["abc"]int // ERROR "invalid array bound|not numeric" -var e [nil]int // ERROR "invalid array bound|not numeric" -var f [e]int // ERROR "invalid array bound|not constant" -var g [1<<65]int // ERROR "array bound is too large|overflows" +var a [10]int // ok +var b [1e1]int // ok +var c [1.5]int // ERROR "truncated" +var d ["abc"]int // ERROR "invalid array bound|not numeric" +var e [nil]int // ERROR "invalid array bound|not numeric" +var f [e]int // ERROR "invalid array bound|not constant" +var g [1 << 65]int // ERROR "array bound is too large|overflows" +var h [len(a)]int // ok + +func ff() string + +var i [len([1]string{ff()})]int // ERROR "non-constant array bound|not constant" diff --git a/test/fixedbugs/bug299.go b/test/fixedbugs/bug299.go index 9646723bf..1067fd147 100644 --- a/test/fixedbugs/bug299.go +++ b/test/fixedbugs/bug299.go @@ -21,7 +21,9 @@ type T struct { // legal according to spec func (p T) m() {} -// not legal according to spec -func (p (T)) f() {} // ERROR "parenthesize|expected" -func (p *(T)) g() {} // ERROR "parenthesize|expected" -func (p (*T)) h() {} // ERROR "parenthesize|expected" +// now legal according to spec +func (p (T)) f() {} +func (p *(T)) g() {} +func (p (*T)) h() {} +func (p (*(T))) i() {} +func ((T),) j() {} diff --git a/test/fixedbugs/bug371.go b/test/fixedbugs/bug371.go index 6329e9635..86c73bf4a 100644 --- a/test/fixedbugs/bug371.go +++ b/test/fixedbugs/bug371.go @@ -8,10 +8,10 @@ package main -type T struct {} +type T struct{} func (t *T) pm() {} -func (t T) m() {} +func (t T) m() {} func main() { p := &T{} @@ -20,5 +20,5 @@ func main() { q := &p q.m() // ERROR "requires explicit dereference" - q.pm() + q.pm() // ERROR "requires explicit dereference" } diff --git a/test/fixedbugs/bug406.go b/test/fixedbugs/bug406.go index c6f8534c9..6df3c5cae 100644 --- a/test/fixedbugs/bug406.go +++ b/test/fixedbugs/bug406.go @@ -14,6 +14,8 @@ type matrix struct { func (a matrix) equal() bool { for _ = range a.e { } + for range a.e { + } return true } diff --git a/test/fixedbugs/bug486.go b/test/fixedbugs/bug486.go new file mode 100644 index 000000000..c1a4723f9 --- /dev/null +++ b/test/fixedbugs/bug486.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. + +// The gccgo lexer had a bug handling nested comments. +// http://gcc.gnu.org/PR61746 +// http://code.google.com/p/gofrontend/issues/detail?id=35 + +package main + +/*// comment +*/ diff --git a/test/fixedbugs/bug487.go b/test/fixedbugs/bug487.go new file mode 100644 index 000000000..eb1ad5e57 --- /dev/null +++ b/test/fixedbugs/bug487.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. + +// The gccgo compiler did not reliably report mismatches between the +// number of function results and the number of expected results. + +package p + +func G() (int, int, int) { + return 0, 0, 0 +} + +func F() { + a, b := G() // ERROR "mismatch" + a, b = G() // ERROR "mismatch" + _, _ = a, b +} + +func H() (int, int) { + return G() // ERROR "too many|mismatch" +} diff --git a/test/fixedbugs/bug488.dir/a.go b/test/fixedbugs/bug488.dir/a.go new file mode 100644 index 000000000..94eaf7f1e --- /dev/null +++ b/test/fixedbugs/bug488.dir/a.go @@ -0,0 +1,7 @@ +// 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 + +var p2 = Printf // ERROR "undefined" diff --git a/test/fixedbugs/bug488.dir/b.go b/test/fixedbugs/bug488.dir/b.go new file mode 100644 index 000000000..21b4c5b54 --- /dev/null +++ b/test/fixedbugs/bug488.dir/b.go @@ -0,0 +1,9 @@ +// 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 + +import . "fmt" + +var p1 = Print diff --git a/test/fixedbugs/bug488.go b/test/fixedbugs/bug488.go new file mode 100644 index 000000000..63a601ed9 --- /dev/null +++ b/test/fixedbugs/bug488.go @@ -0,0 +1,12 @@ +// errorcheckdir + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The gccgo compiler had a bug: if one file in a package did a dot +// import, then an earlier file in the package would incorrectly +// resolve to the imported names rather than reporting undefined +// errors. + +package ignored diff --git a/test/fixedbugs/bug489.go b/test/fixedbugs/bug489.go new file mode 100644 index 000000000..4cf19e059 --- /dev/null +++ b/test/fixedbugs/bug489.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The gccgo compiler had a bug: mentioning a function type in an +// expression in a function literal messed up the list of variables +// referenced in enclosing functions. + +package main + +func main() { + v1, v2 := 0, 0 + f := func() { + a := v1 + g := (func())(nil) + b := v2 + _, _, _ = a, g, b + } + _, _, _ = v1, v2, f +} diff --git a/test/fixedbugs/bug490.go b/test/fixedbugs/bug490.go new file mode 100644 index 000000000..7d05f3945 --- /dev/null +++ b/test/fixedbugs/bug490.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The gccgo compiler used to crash building a comparison between an +// interface and an empty struct literal. + +package p + +type S struct{} + +func F(v interface{}) bool { + return v == S{} +} diff --git a/test/fixedbugs/bug491.go b/test/fixedbugs/bug491.go new file mode 100644 index 000000000..f4b58af1e --- /dev/null +++ b/test/fixedbugs/bug491.go @@ -0,0 +1,110 @@ +// run + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test order of calls to builtin functions. +// Discovered during CL 144530045 review. + +package main + +func main() { + // append + { + x := make([]int, 0) + f := func() int { x = make([]int, 2); return 2 } + a, b, c := append(x, 1), f(), append(x, 1) + if len(a) != 1 || len(c) != 3 { + bug() + println("append call not ordered:", len(a), b, len(c)) + } + } + + // cap + { + x := make([]int, 1) + f := func() int { x = make([]int, 3); return 2 } + a, b, c := cap(x), f(), cap(x) + if a != 1 || c != 3 { + bug() + println("cap call not ordered:", a, b, c) + } + } + + // complex + { + x := 1.0 + f := func() int { x = 3; return 2 } + a, b, c := complex(x, 0), f(), complex(x, 0) + if real(a) != 1 || real(c) != 3 { + bug() + println("complex call not ordered:", a, b, c) + } + } + + // copy + { + tmp := make([]int, 100) + x := make([]int, 1) + f := func() int { x = make([]int, 3); return 2 } + a, b, c := copy(tmp, x), f(), copy(tmp, x) + if a != 1 || c != 3 { + bug() + println("copy call not ordered:", a, b, c) + } + } + + // imag + { + x := 1i + f := func() int { x = 3i; return 2 } + a, b, c := imag(x), f(), imag(x) + if a != 1 || c != 3 { + bug() + println("imag call not ordered:", a, b, c) + } + } + + // len + { + x := make([]int, 1) + f := func() int { x = make([]int, 3); return 2 } + a, b, c := len(x), f(), len(x) + if a != 1 || c != 3 { + bug() + println("len call not ordered:", a, b, c) + } + } + + // make + { + x := 1 + f := func() int { x = 3; return 2 } + a, b, c := make([]int, x), f(), make([]int, x) + if len(a) != 1 || len(c) != 3 { + bug() + println("make call not ordered:", len(a), b, len(c)) + } + } + + // real + { + x := 1 + 0i + f := func() int { x = 3; return 2 } + a, b, c := real(x), f(), real(x) + if a != 1 || c != 3 { + bug() + println("real call not ordered:", a, b, c) + } + } +} + +var bugged = false + +func bug() { + if !bugged { + println("BUG") + bugged = true + } +}
\ No newline at end of file diff --git a/test/fixedbugs/issue4232.go b/test/fixedbugs/issue4232.go index e5daa6562..755b1b1de 100644 --- a/test/fixedbugs/issue4232.go +++ b/test/fixedbugs/issue4232.go @@ -4,6 +4,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// issue 4232 +// issue 7200 + package p func f() { @@ -12,22 +15,42 @@ func f() { _ = a[-1:] // ERROR "invalid slice index -1|index out of bounds" _ = a[:-1] // ERROR "invalid slice index -1|index out of bounds" _ = a[10] // ERROR "invalid array index 10|index out of bounds" + _ = a[9:10] + _ = a[10:10] + _ = a[9:12] // ERROR "invalid slice index 12|index out of bounds" + _ = a[11:12] // ERROR "invalid slice index 11|index out of bounds" + _ = a[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" var s []int _ = s[-1] // ERROR "invalid slice index -1|index out of bounds" _ = s[-1:] // ERROR "invalid slice index -1|index out of bounds" _ = s[:-1] // ERROR "invalid slice index -1|index out of bounds" _ = s[10] + _ = s[9:10] + _ = s[10:10] + _ = s[9:12] + _ = s[11:12] + _ = s[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" - const c = "foo" + const c = "foofoofoof" _ = c[-1] // ERROR "invalid string index -1|index out of bounds" _ = c[-1:] // ERROR "invalid slice index -1|index out of bounds" _ = c[:-1] // ERROR "invalid slice index -1|index out of bounds" - _ = c[3] // ERROR "invalid string index 3|index out of bounds" + _ = c[10] // ERROR "invalid string index 10|index out of bounds" + _ = c[9:10] + _ = c[10:10] + _ = c[9:12] // ERROR "invalid slice index 12|index out of bounds" + _ = c[11:12] // ERROR "invalid slice index 11|index out of bounds" + _ = c[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" var t string _ = t[-1] // ERROR "invalid string index -1|index out of bounds" _ = t[-1:] // ERROR "invalid slice index -1|index out of bounds" _ = t[:-1] // ERROR "invalid slice index -1|index out of bounds" - _ = t[3] + _ = t[10] + _ = t[9:10] + _ = t[10:10] + _ = t[9:12] + _ = t[11:12] + _ = t[1<<100 : 1<<110] // ERROR "overflows int" "invalid slice index 1 << 100|index out of bounds" } diff --git a/test/fixedbugs/issue4388.go b/test/fixedbugs/issue4388.go index 2e052e138..b18c98bac 100644 --- a/test/fixedbugs/issue4388.go +++ b/test/fixedbugs/issue4388.go @@ -17,18 +17,18 @@ type T struct { } func f1() { - // The 4 here and below depends on the number of internal runtime frames + // The 5 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) + defer checkLine(5) var t *T var c io.Closer = t c.Close() } func f2() { - defer checkLine(4) + defer checkLine(5) var t T var c io.Closer = t c.Close() diff --git a/test/fixedbugs/issue5856.go b/test/fixedbugs/issue5856.go index 35cadf8c9..78ca3b9f6 100644 --- a/test/fixedbugs/issue5856.go +++ b/test/fixedbugs/issue5856.go @@ -29,7 +29,7 @@ func f() { } func g() { - _, file, line, _ := runtime.Caller(2) + _, file, line, _ := runtime.Caller(3) if !strings.HasSuffix(file, "issue5856.go") || line != 28 { fmt.Printf("BUG: defer called from %s:%d, want issue5856.go:28\n", file, line) os.Exit(1) diff --git a/test/fixedbugs/issue6703a.go b/test/fixedbugs/issue6703a.go new file mode 100644 index 000000000..d4c008f83 --- /dev/null +++ b/test/fixedbugs/issue6703a.go @@ -0,0 +1,16 @@ +// 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. + +// Check for cycles in a function value. + +package funcvalue + +func fx() int { + _ = x + return 0 +} + +var x = fx // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703b.go b/test/fixedbugs/issue6703b.go new file mode 100644 index 000000000..326b5839a --- /dev/null +++ b/test/fixedbugs/issue6703b.go @@ -0,0 +1,16 @@ +// 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. + +// Check for cycles in a function call. + +package funccall + +func fx() int { + _ = x + return 0 +} + +var x = fx() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703c.go b/test/fixedbugs/issue6703c.go new file mode 100644 index 000000000..473576475 --- /dev/null +++ b/test/fixedbugs/issue6703c.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in a method expression. + +package methexpr + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T.m // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703d.go b/test/fixedbugs/issue6703d.go new file mode 100644 index 000000000..0a1952f78 --- /dev/null +++ b/test/fixedbugs/issue6703d.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in a method expression call. + +package methexprcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T.m(0) // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703e.go b/test/fixedbugs/issue6703e.go new file mode 100644 index 000000000..416066e85 --- /dev/null +++ b/test/fixedbugs/issue6703e.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in the method value of a value literal. + +package litmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T(0).m // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703f.go b/test/fixedbugs/issue6703f.go new file mode 100644 index 000000000..30238297b --- /dev/null +++ b/test/fixedbugs/issue6703f.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in the method call of a value literal. + +package litmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var x = T(0).m() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703g.go b/test/fixedbugs/issue6703g.go new file mode 100644 index 000000000..002b5a636 --- /dev/null +++ b/test/fixedbugs/issue6703g.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. + +// Check for cycles in an embedded method expression. + +package embedmethexpr + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E.m // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703h.go b/test/fixedbugs/issue6703h.go new file mode 100644 index 000000000..234ccb365 --- /dev/null +++ b/test/fixedbugs/issue6703h.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. + +// Check for cycles when calling an embedded method expression. + +package embedmethexprcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E.m(E{0}) // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703i.go b/test/fixedbugs/issue6703i.go new file mode 100644 index 000000000..78b4d4980 --- /dev/null +++ b/test/fixedbugs/issue6703i.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. + +// Check for cycles in an embedded struct literal's method value. + +package embedlitmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E{}.m // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703j.go b/test/fixedbugs/issue6703j.go new file mode 100644 index 000000000..a7f63f748 --- /dev/null +++ b/test/fixedbugs/issue6703j.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. + +// Check for cycles in an embedded struct literal's method call. + +package embedlitmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var x = E{}.m() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703k.go b/test/fixedbugs/issue6703k.go new file mode 100644 index 000000000..19c61078c --- /dev/null +++ b/test/fixedbugs/issue6703k.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. + +// Check for cycles in a method value. + +package methvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var ( + t T + x = t.m // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703l.go b/test/fixedbugs/issue6703l.go new file mode 100644 index 000000000..3f4ca3147 --- /dev/null +++ b/test/fixedbugs/issue6703l.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. + +// Check for cycles in a method call. + +package methcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +var ( + t T + x = t.m() // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703m.go b/test/fixedbugs/issue6703m.go new file mode 100644 index 000000000..d80959cdc --- /dev/null +++ b/test/fixedbugs/issue6703m.go @@ -0,0 +1,25 @@ +// 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. + +// Check for cycles in the method value of a value returned from a function call. + +package funcmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func f() T { + return T(0) +} + +var ( + t T + x = f().m // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703n.go b/test/fixedbugs/issue6703n.go new file mode 100644 index 000000000..2c623f219 --- /dev/null +++ b/test/fixedbugs/issue6703n.go @@ -0,0 +1,25 @@ +// 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. + +// Check for cycles in the method call of a value returned from a function call. + +package funcmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func f() T { + return T(0) +} + +var ( + t T + x = f().m() // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703o.go b/test/fixedbugs/issue6703o.go new file mode 100644 index 000000000..efc894737 --- /dev/null +++ b/test/fixedbugs/issue6703o.go @@ -0,0 +1,23 @@ +// 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. + +// Check for cycles in an embedded struct's method value. + +package embedmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var ( + e E + x = e.m // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703p.go b/test/fixedbugs/issue6703p.go new file mode 100644 index 000000000..dad88f634 --- /dev/null +++ b/test/fixedbugs/issue6703p.go @@ -0,0 +1,23 @@ +// 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. + +// Check for cycles in an embedded struct's method call. + +package embedmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +type E struct{ T } + +var ( + e E + x = e.m() // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703q.go b/test/fixedbugs/issue6703q.go new file mode 100644 index 000000000..7bd748aaa --- /dev/null +++ b/test/fixedbugs/issue6703q.go @@ -0,0 +1,28 @@ +// 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. + +// Check for cycles in the method value of an embedded struct returned +// from a function call. + +package funcembedmethvalue + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func g() E { + return E{0} +} + +type E struct{ T } + +var ( + e E + x = g().m // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703r.go b/test/fixedbugs/issue6703r.go new file mode 100644 index 000000000..669846241 --- /dev/null +++ b/test/fixedbugs/issue6703r.go @@ -0,0 +1,28 @@ +// 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. + +// Check for cycles in the method call of an embedded struct returned +// from a function call. + +package funcembedmethcall + +type T int + +func (T) m() int { + _ = x + return 0 +} + +func g() E { + return E{0} +} + +type E struct{ T } + +var ( + e E + x = g().m() // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703s.go b/test/fixedbugs/issue6703s.go new file mode 100644 index 000000000..6aa28483a --- /dev/null +++ b/test/fixedbugs/issue6703s.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in a pointer method expression. + +package ptrmethexpr + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T).pm // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703t.go b/test/fixedbugs/issue6703t.go new file mode 100644 index 000000000..bad65ad16 --- /dev/null +++ b/test/fixedbugs/issue6703t.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in the call of a pointer method expression. + +package ptrmethexprcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T).pm(nil) // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703u.go b/test/fixedbugs/issue6703u.go new file mode 100644 index 000000000..b6813b771 --- /dev/null +++ b/test/fixedbugs/issue6703u.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in a pointer literal's method value. + +package ptrlitmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T)(nil).pm // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703v.go b/test/fixedbugs/issue6703v.go new file mode 100644 index 000000000..a1b3711bb --- /dev/null +++ b/test/fixedbugs/issue6703v.go @@ -0,0 +1,18 @@ +// 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. + +// Check for cycles in a pointer literal's method call. + +package ptrlitmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var x = (*T)(nil).pm() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703w.go b/test/fixedbugs/issue6703w.go new file mode 100644 index 000000000..d4733deba --- /dev/null +++ b/test/fixedbugs/issue6703w.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. + +// Check for cycles in a pointer value's method value. + +package ptrmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var ( + p *T + x = p.pm // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703x.go b/test/fixedbugs/issue6703x.go new file mode 100644 index 000000000..8008b8c37 --- /dev/null +++ b/test/fixedbugs/issue6703x.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. + +// Check for cycles in a pointer value's method call. + +package ptrmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +var ( + p *T + x = p.pm() // ERROR "initialization loop|depends upon itself" +) diff --git a/test/fixedbugs/issue6703y.go b/test/fixedbugs/issue6703y.go new file mode 100644 index 000000000..ac4526dda --- /dev/null +++ b/test/fixedbugs/issue6703y.go @@ -0,0 +1,23 @@ +// 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. + +// Check for cycles in the method value of a pointer value returned +// from a function call. + +package funcptrmethvalue + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +func pf() *T { + return nil +} + +var x = pf().pm // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue6703z.go b/test/fixedbugs/issue6703z.go new file mode 100644 index 000000000..d4c17e13a --- /dev/null +++ b/test/fixedbugs/issue6703z.go @@ -0,0 +1,23 @@ +// 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. + +// Check for cycles in the method call of a pointer value returned +// from a function call. + +package funcptrmethcall + +type T int + +func (*T) pm() int { + _ = x + return 0 +} + +func pf() *T { + return nil +} + +var x = pf().pm() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/issue7690.go b/test/fixedbugs/issue7690.go new file mode 100644 index 000000000..4ad9e8622 --- /dev/null +++ b/test/fixedbugs/issue7690.go @@ -0,0 +1,49 @@ +// 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 7690 - Stack and other routines did not back up initial PC +// into CALL instruction, instead reporting line number of next instruction, +// which might be on a different line. + +package main + +import ( + "bytes" + "regexp" + "runtime" + "strconv" +) + +func main() { + buf1 := make([]byte, 1000) + buf2 := make([]byte, 1000) + + runtime.Stack(buf1, false) // CALL is last instruction on this line + n := runtime.Stack(buf2, false) // CALL is followed by load of result from stack + + buf1 = buf1[:bytes.IndexByte(buf1, 0)] + buf2 = buf2[:n] + + re := regexp.MustCompile(`(?m)^main\.main\(\)\n.*/issue7690.go:([0-9]+)`) + m1 := re.FindStringSubmatch(string(buf1)) + if m1 == nil { + println("BUG: cannot find main.main in first trace") + return + } + m2 := re.FindStringSubmatch(string(buf2)) + if m2 == nil { + println("BUG: cannot find main.main in second trace") + return + } + + n1, _ := strconv.Atoi(m1[1]) + n2, _ := strconv.Atoi(m2[1]) + if n1+1 != n2 { + println("BUG: expect runtime.Stack on back to back lines, have", n1, n2) + println(string(buf1)) + println(string(buf2)) + } +} diff --git a/test/fixedbugs/issue7760.go b/test/fixedbugs/issue7760.go new file mode 100644 index 000000000..cccae4891 --- /dev/null +++ b/test/fixedbugs/issue7760.go @@ -0,0 +1,25 @@ +// 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. + +// Verify that pointers can't be used as constants. + +package main + +import "unsafe" + +type myPointer unsafe.Pointer + +const _ = unsafe.Pointer(uintptr(1)) // ERROR "is not (a )?constant" +const _ = myPointer(uintptr(1)) // ERROR "is not (a )?constant" + +const _ = (*int)(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant" +const _ = (*int)(myPointer(uintptr(1))) // ERROR "is not (a )?constant" + +const _ = uintptr(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant" +const _ = uintptr(myPointer(uintptr(1))) // ERROR "is not (a )?constant" + +const _ = []byte("") // ERROR "is not (a )?constant" +const _ = []rune("") // ERROR "is not (a )?constant" diff --git a/test/fixedbugs/issue8017.go b/test/fixedbugs/issue8017.go new file mode 100644 index 000000000..22056e08c --- /dev/null +++ b/test/fixedbugs/issue8017.go @@ -0,0 +1,26 @@ +// 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. + +// Issues 8017 and 8058: walk modifies nodes generated +// by slicelit and causes an internal error afterwards +// when gen_as_init parses it back. + +package main + +func F() { + var ch chan int + select { + case <-ch: + case <-make(chan int, len([2][]int{([][]int{})[len(ch)], []int{}})): + } +} + +func G() { + select { + case <-([1][]chan int{[]chan int{}})[0][0]: + default: + } +} diff --git a/test/fixedbugs/issue8060.dir/a.go b/test/fixedbugs/issue8060.dir/a.go new file mode 100644 index 000000000..22ba69ee1 --- /dev/null +++ b/test/fixedbugs/issue8060.dir/a.go @@ -0,0 +1,7 @@ +// 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 + +var A = []*[2][1]float64{} diff --git a/test/fixedbugs/issue8060.dir/b.go b/test/fixedbugs/issue8060.dir/b.go new file mode 100644 index 000000000..85fb6ec7d --- /dev/null +++ b/test/fixedbugs/issue8060.dir/b.go @@ -0,0 +1,13 @@ +// 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 X = a.A + +func b() { + _ = [3][1]float64{} +} diff --git a/test/fixedbugs/issue8060.go b/test/fixedbugs/issue8060.go new file mode 100644 index 000000000..ec52659e6 --- /dev/null +++ b/test/fixedbugs/issue8060.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 8060: internal compiler error. + +package ignored diff --git a/test/fixedbugs/issue8074.go b/test/fixedbugs/issue8074.go new file mode 100644 index 000000000..aedab240e --- /dev/null +++ b/test/fixedbugs/issue8074.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 8074. +// was "cannot take the address of 1" + +package main + +func main() { + a := make([]byte, 10) + m := make(map[float64][]byte) + go copy(a, m[1.0]) +} diff --git a/test/fixedbugs/issue8079.go b/test/fixedbugs/issue8079.go new file mode 100644 index 000000000..994999bf6 --- /dev/null +++ b/test/fixedbugs/issue8079.go @@ -0,0 +1,11 @@ +// 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 8079: gccgo crashes when compiling interface with blank type name. + +package p + +type _ interface{} diff --git a/test/fixedbugs/issue8280.dir/a.go b/test/fixedbugs/issue8280.dir/a.go new file mode 100644 index 000000000..588536e79 --- /dev/null +++ b/test/fixedbugs/issue8280.dir/a.go @@ -0,0 +1,3 @@ +package a + +var Bar = func() (_ int) { return 0 } diff --git a/test/fixedbugs/issue8280.dir/b.go b/test/fixedbugs/issue8280.dir/b.go new file mode 100644 index 000000000..c46c55458 --- /dev/null +++ b/test/fixedbugs/issue8280.dir/b.go @@ -0,0 +1,5 @@ +package b + +import "./a" + +var foo = a.Bar diff --git a/test/fixedbugs/issue8280.go b/test/fixedbugs/issue8280.go new file mode 100644 index 000000000..91256c852 --- /dev/null +++ b/test/fixedbugs/issue8280.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 8280: cannot import package exporting a func var returning a result named _ + +package ignored diff --git a/test/fixedbugs/issue8311.go b/test/fixedbugs/issue8311.go new file mode 100644 index 000000000..dd928566d --- /dev/null +++ b/test/fixedbugs/issue8311.go @@ -0,0 +1,16 @@ +// 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 8311. +// error for x++ should say x++ not x += 1 + +package p + +func f() { + var x []byte + x++ // ERROR "invalid operation: x[+][+]" + +} diff --git a/test/fixedbugs/issue8336.go b/test/fixedbugs/issue8336.go new file mode 100644 index 000000000..26bdeabb2 --- /dev/null +++ b/test/fixedbugs/issue8336.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 8336. Order of evaluation of receive channels in select. + +package main + +type X struct { + c chan int +} + +func main() { + defer func() { + recover() + }() + var x *X + select { + case <-x.c: // should fault and panic before foo is called + case <-foo(): + } +} + +func foo() chan int { + println("BUG: foo must not be called") + return make(chan int) +} diff --git a/test/fixedbugs/issue8347.go b/test/fixedbugs/issue8347.go new file mode 100644 index 000000000..0828ccf06 --- /dev/null +++ b/test/fixedbugs/issue8347.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 main() { + c := make(chan bool, 1) + ok := true + for i := 0; i < 12; i++ { + select { + case _, ok = <-c: + if i < 10 && !ok { + panic("BUG") + } + default: + } + if i < 10 && !ok { + panic("BUG") + } + if i >= 10 && ok { + close(c) + } + } +} diff --git a/test/fixedbugs/issue8475.go b/test/fixedbugs/issue8475.go new file mode 100644 index 000000000..e69794534 --- /dev/null +++ b/test/fixedbugs/issue8475.go @@ -0,0 +1,25 @@ +// build + +// 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 8745: comma-ok assignments should produce untyped bool as 2nd result. + +package main + +type mybool bool + +func main() { + var ok mybool + _ = ok + + var i interface{} + _, ok = i.(int) + + var m map[int]int + _, ok = m[0] + + var c chan int + _, ok = <-c +} diff --git a/test/fixedbugs/issue8507.go b/test/fixedbugs/issue8507.go new file mode 100644 index 000000000..00a14aa88 --- /dev/null +++ b/test/fixedbugs/issue8507.go @@ -0,0 +1,16 @@ +// 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 8507 +// used to call algtype on invalid recursive type and get into infinite recursion + +package p + +type T struct{ T } // ERROR "invalid recursive type T" + +func f() { + println(T{} == T{}) +} diff --git a/test/fixedbugs/issue8612.go b/test/fixedbugs/issue8612.go new file mode 100644 index 000000000..93370cf66 --- /dev/null +++ b/test/fixedbugs/issue8612.go @@ -0,0 +1,34 @@ +//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. + +// Gccgo had a bug comparing a struct or array value with an interface +// values, when the struct or array was not addressable. + +package p + +type A [10]int + +type S struct { + i int +} + +func F1() S { + return S{0} +} + +func F2() A { + return A{} +} + +func Cmp(v interface{}) bool { + if F1() == v { + return true + } + if F2() == v { + return true + } + return false +} diff --git a/test/fixedbugs/issue8761.go b/test/fixedbugs/issue8761.go new file mode 100644 index 000000000..badf639fc --- /dev/null +++ b/test/fixedbugs/issue8761.go @@ -0,0 +1,26 @@ +// 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 8761 +// used to confuse code generator into using temporary before initialization. +// caused 'variable live at entry' error in liveness analysis. + +package p + +func _() { + type C chan int + _ = [1][]C{[]C{make(chan int)}} +} + +func _() { + type C interface{} + _ = [1][]C{[]C{recover()}} +} + +func _() { + type C *int + _ = [1][]C{[]C{new(int)}} +} diff --git a/test/fixedbugs/issue8947.go b/test/fixedbugs/issue8947.go new file mode 100644 index 000000000..f40c02e99 --- /dev/null +++ b/test/fixedbugs/issue8947.go @@ -0,0 +1,53 @@ +// 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. + +// Some uses of zeroed constants in non-assignment +// expressions broke with our more aggressive zeroing +// of assignments (internal compiler errors). + +package main + +func f1() { + type T [2]int + p := T{0, 1} + switch p { + case T{0, 0}: + panic("wrong1") + case T{0, 1}: + // ok + default: + panic("wrong2") + } + + if p == (T{0, 0}) { + panic("wrong3") + } else if p == (T{0, 1}) { + // ok + } else { + panic("wrong4") + } +} + +type T struct { + V int +} + +var X = T{}.V + +func f2() { + var x = T{}.V + if x != 0 { + panic("wrongx") + } + if X != 0 { + panic("wrongX") + } +} + +func main() { + f1() + f2() +} diff --git a/test/fixedbugs/issue8961.go b/test/fixedbugs/issue8961.go new file mode 100644 index 000000000..fbfb7e67f --- /dev/null +++ b/test/fixedbugs/issue8961.go @@ -0,0 +1,20 @@ +// 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 8961. Empty composite literals to small globals were not filled in +package main + +type small struct { a int } +var foo small + +func main() { + foo.a = 1 + foo = small{} + if foo.a != 0 { + println("expected foo.a to be 0, was", foo.a) + panic("composite literal not filled in") + } +} diff --git a/test/fixedbugs/issue9006.go b/test/fixedbugs/issue9006.go new file mode 100644 index 000000000..c559f58f1 --- /dev/null +++ b/test/fixedbugs/issue9006.go @@ -0,0 +1,37 @@ +// 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 + +type T1 struct { + X int +} + +func NewT1(x int) T1 { return T1{x} } + +type T2 int + +func NewT2(x int) T2 { return T2(x) } + +func main() { + switch (T1{}) { + case NewT1(1): + panic("bad1") + case NewT1(0): + // ok + default: + panic("bad2") + } + + switch T2(0) { + case NewT2(2): + panic("bad3") + case NewT2(0): + // ok + default: + panic("bad4") + } +} diff --git a/test/fixedbugs/issue9110.go b/test/fixedbugs/issue9110.go new file mode 100644 index 000000000..729463305 --- /dev/null +++ b/test/fixedbugs/issue9110.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. + +// Scenario that used to leak arbitrarily many SudoG structs. +// See golang.org/issue/9110. + +package main + +import ( + "runtime" + "runtime/debug" + "sync" + "time" +) + +func main() { + debug.SetGCPercent(1000000) // only GC when we ask for GC + + var stats, stats1, stats2 runtime.MemStats + + release := func() {} + for i := 0; i < 20; i++ { + if i == 10 { + // Should be warmed up by now. + runtime.ReadMemStats(&stats1) + } + + c := make(chan int) + for i := 0; i < 10; i++ { + go func() { + select { + case <-c: + case <-c: + case <-c: + } + }() + } + time.Sleep(1 * time.Millisecond) + release() + + close(c) // let select put its sudog's into the cache + time.Sleep(1 * time.Millisecond) + + // pick up top sudog + var cond1 sync.Cond + var mu1 sync.Mutex + cond1.L = &mu1 + go func() { + mu1.Lock() + cond1.Wait() + mu1.Unlock() + }() + time.Sleep(1 * time.Millisecond) + + // pick up next sudog + var cond2 sync.Cond + var mu2 sync.Mutex + cond2.L = &mu2 + go func() { + mu2.Lock() + cond2.Wait() + mu2.Unlock() + }() + time.Sleep(1 * time.Millisecond) + + // put top sudog back + cond1.Broadcast() + time.Sleep(1 * time.Millisecond) + + // drop cache on floor + runtime.GC() + + // release cond2 after select has gotten to run + release = func() { + cond2.Broadcast() + time.Sleep(1 * time.Millisecond) + } + } + + runtime.GC() + + runtime.ReadMemStats(&stats2) + + if int(stats2.HeapObjects)-int(stats1.HeapObjects) > 20 { // normally at most 1 or 2; was 300 with leak + print("BUG: object leak: ", stats.HeapObjects, " -> ", stats1.HeapObjects, " -> ", stats2.HeapObjects, "\n") + } +} |