diff options
Diffstat (limited to 'test/fixedbugs')
33 files changed, 671 insertions, 23 deletions
diff --git a/test/fixedbugs/bug040.go b/test/fixedbugs/bug040.go index 007f47f9f..d2cf88afc 100644 --- a/test/fixedbugs/bug040.go +++ b/test/fixedbugs/bug040.go @@ -7,5 +7,5 @@ package main func f (x, // GCCGO_ERROR "previous" - x int) { // ERROR "redeclared|redefinition" "duplicate" + x int) { // ERROR "duplicate argument|redefinition" } diff --git a/test/fixedbugs/bug086.go b/test/fixedbugs/bug086.go index fc69e0e3f..f03982b30 100644 --- a/test/fixedbugs/bug086.go +++ b/test/fixedbugs/bug086.go @@ -6,12 +6,12 @@ package main -func f() int { // ERROR "return|control" +func f() int { // GCCGO_ERROR "control" if false { return 0; } // we should not be able to return successfully w/o a return statement -} +} // GC_ERROR "return" func main() { print(f(), "\n"); diff --git a/test/fixedbugs/bug342.go b/test/fixedbugs/bug342.go index 5f1efbdfe..ffcb66811 100644 --- a/test/fixedbugs/bug342.go +++ b/test/fixedbugs/bug342.go @@ -9,11 +9,7 @@ package p type a interface { - foo(x int) (x int) // ERROR "redeclared|redefinition" -} - -var b interface { - bar(y int) (y int) // ERROR "redeclared|redefinition" + foo(x int) (x int) // ERROR "duplicate argument|redefinition" } /* diff --git a/test/fixedbugs/bug412.go b/test/fixedbugs/bug412.go index 8dd0a5fcc..c7ddc0cac 100644 --- a/test/fixedbugs/bug412.go +++ b/test/fixedbugs/bug412.go @@ -7,8 +7,8 @@ package p type t struct { - x int // ERROR "duplicate field x|duplicate field name .x." - x int + x int // GCCGO_ERROR "duplicate field name .x." + x int // GC_ERROR "duplicate field x" } func f(t *t) int { diff --git a/test/fixedbugs/bug469.go b/test/fixedbugs/bug469.go deleted file mode 100644 index 71157a4c4..000000000 --- a/test/fixedbugs/bug469.go +++ /dev/null @@ -1,13 +0,0 @@ -// 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. - -// The gccgo compiler would complain about a redefinition of i, but -// the spec imposes no requirements on parameter names in a function -// type. - -package p - -type F func(i int) (i int) diff --git a/test/fixedbugs/bug474.go b/test/fixedbugs/bug474.go new file mode 100644 index 000000000..b8264872a --- /dev/null +++ b/test/fixedbugs/bug474.go @@ -0,0 +1,29 @@ +// 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. + +// Bug in method values: escape analysis was off. + +package main + +import "sync" + +var called = false + +type T struct { + once sync.Once +} + +func (t *T) M() { + called = true +} + +func main() { + var t T + t.once.Do(t.M) + if !called { + panic("not called") + } +} diff --git a/test/fixedbugs/issue4663.go b/test/fixedbugs/issue4663.go index b3d660287..edaee93c5 100644 --- a/test/fixedbugs/issue4663.go +++ b/test/fixedbugs/issue4663.go @@ -11,4 +11,5 @@ package main func a(b int) int64 { b // ERROR "not used" + return 0 } diff --git a/test/fixedbugs/issue4813.go b/test/fixedbugs/issue4813.go new file mode 100644 index 000000000..0ca9d3f72 --- /dev/null +++ b/test/fixedbugs/issue4813.go @@ -0,0 +1,52 @@ +// 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. + +// Issue 4813: use of constant floats as indices. + +package main + +var A [3]int +var S []int +var T string + +const ( + i = 1 + f = 2.0 + f2 = 2.1 + c = complex(2, 0) + c2 = complex(2, 1) +) + +var ( + vf = f + vc = c +) + +var ( + a1 = A[i] + a2 = A[f] + a3 = A[f2] // ERROR "truncated" + a4 = A[c] + a5 = A[c2] // ERROR "truncated" + a6 = A[vf] // ERROR "non-integer" + a7 = A[vc] // ERROR "non-integer" + + s1 = S[i] + s2 = S[f] + s3 = S[f2] // ERROR "truncated" + s4 = S[c] + s5 = S[c2] // ERROR "truncated" + s6 = S[vf] // ERROR "non-integer" + s7 = S[vc] // ERROR "non-integer" + + t1 = T[i] + t2 = T[f] + t3 = T[f2] // ERROR "truncated" + t4 = T[c] + t5 = T[c2] // ERROR "truncated" + t6 = T[vf] // ERROR "non-integer" + t7 = T[vc] // ERROR "non-integer" +) diff --git a/test/fixedbugs/issue4909a.go b/test/fixedbugs/issue4909a.go new file mode 100644 index 000000000..aefe2d645 --- /dev/null +++ b/test/fixedbugs/issue4909a.go @@ -0,0 +1,35 @@ +// 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. + +// Issue 4909: compiler incorrectly accepts unsafe.Offsetof(t.x) +// where x is a field of an embedded pointer field. + +package p + +import ( + "unsafe" +) + +type T struct { + A int + *B +} + +func (t T) Method() {} + +type B struct { + X, Y int +} + +var t T +var p *T + +const N1 = unsafe.Offsetof(t.X) // ERROR "indirection" +const N2 = unsafe.Offsetof(p.X) // ERROR "indirection" +const N3 = unsafe.Offsetof(t.B.X) // valid +const N4 = unsafe.Offsetof(p.B.X) // valid +const N5 = unsafe.Offsetof(t.Method) // ERROR "method value" +const N6 = unsafe.Offsetof(p.Method) // ERROR "method value" diff --git a/test/fixedbugs/issue4909b.go b/test/fixedbugs/issue4909b.go new file mode 100644 index 000000000..0f594e3db --- /dev/null +++ b/test/fixedbugs/issue4909b.go @@ -0,0 +1,80 @@ +// errorcheckoutput + +package main + +import "fmt" + +// We are going to define 256 types T(n), +// such that T(n) embeds T(2n) and *T(2n+1). + +func main() { + fmt.Printf("// errorcheck\n\n") + fmt.Printf("package p\n\n") + fmt.Println(`import "unsafe"`) + + // Dump types. + for n := 1; n < 256; n++ { + writeStruct(n) + } + // Dump leaves + for n := 256; n < 512; n++ { + fmt.Printf("type T%d int\n", n) + } + + fmt.Printf("var t T1\n") + fmt.Printf("var p *T1\n") + + // Simple selectors + for n := 2; n < 256; n++ { + writeDot(n) + } + + // Double selectors + for n := 128; n < 256; n++ { + writeDot(n/16, n) + } + + // Triple selectors + for n := 128; n < 256; n++ { + writeDot(n/64, n/8, n) + } +} + +const structTpl = ` +type T%d struct { + A%d int + T%d + *T%d +} +` + +func writeStruct(n int) { + fmt.Printf(structTpl, n, n, 2*n, 2*n+1) +} + +func writeDot(ns ...int) { + for _, root := range []string{"t", "p"} { + fmt.Printf("const _ = unsafe.Offsetof(%s", root) + for _, n := range ns { + fmt.Printf(".T%d", n) + } + // Does it involve an indirection? + nlast := ns[len(ns)-1] + nprev := 1 + if len(ns) > 1 { + nprev = ns[len(ns)-2] + } + isIndirect := false + for n := nlast / 2; n > nprev; n /= 2 { + if n%2 == 1 { + isIndirect = true + break + } + } + fmt.Print(")") + if isIndirect { + fmt.Print(` // ERROR "indirection"`) + } + fmt.Print("\n") + } +} diff --git a/test/fixedbugs/issue4964.dir/a.go b/test/fixedbugs/issue4964.dir/a.go new file mode 100644 index 000000000..2b9e44e35 --- /dev/null +++ b/test/fixedbugs/issue4964.dir/a.go @@ -0,0 +1,27 @@ +// 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 + +var global, global2 *int + +type T struct { + Pointer *int +} + +func dontinline() {} + +func Store(t *T) { + global = t.Pointer + dontinline() +} + +func Store2(t *T) { + global2 = t.Pointer + dontinline() +} + +func Get() *int { + return global +} diff --git a/test/fixedbugs/issue4964.dir/b.go b/test/fixedbugs/issue4964.dir/b.go new file mode 100644 index 000000000..42a6f1d76 --- /dev/null +++ b/test/fixedbugs/issue4964.dir/b.go @@ -0,0 +1,34 @@ +// 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" + +func F() { + // store 1 in a.global + x, y := 1, 2 + t := a.T{Pointer: &x} + a.Store(&t) + _ = y +} + +func G() { + // store 4 in a.global2 + x, y := 3, 4 + t := a.T{Pointer: &y} + a.Store2(&t) + _ = x +} + +func main() { + F() + G() + p := a.Get() + n := *p + if n != 1 { + println(n, "!= 1") + panic("n != 1") + } +} diff --git a/test/fixedbugs/issue4964.go b/test/fixedbugs/issue4964.go new file mode 100644 index 000000000..8291d1bb9 --- /dev/null +++ b/test/fixedbugs/issue4964.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 4964: exported escape analysis result is not enough +// for cross package analysis. + +package ignored diff --git a/test/fixedbugs/issue5002.go b/test/fixedbugs/issue5002.go new file mode 100644 index 000000000..1e74fa1a1 --- /dev/null +++ b/test/fixedbugs/issue5002.go @@ -0,0 +1,16 @@ +// build + +// 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 5002: 8g produces invalid CMPL $0, $0. +// Used to fail at link time. + +package main + +func main() { + var y int64 + if y%1 == 0 { + } +} diff --git a/test/fixedbugs/issue5056.go b/test/fixedbugs/issue5056.go new file mode 100644 index 000000000..a2cde2a50 --- /dev/null +++ b/test/fixedbugs/issue5056.go @@ -0,0 +1,34 @@ +// 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 5056: escape analysis not applied to wrapper functions + +package main + +type Foo int16 + +func (f Foo) Esc() *int{ + x := int(f) + return &x +} + +type iface interface { + Esc() *int +} + +var bar, foobar *int + +func main() { + var quux iface + var x Foo + + quux = x + bar = quux.Esc() + foobar = quux.Esc() + if bar == foobar { + panic("bar == foobar") + } +} diff --git a/test/fixedbugs/issue5089.go b/test/fixedbugs/issue5089.go new file mode 100644 index 000000000..14d6bde98 --- /dev/null +++ b/test/fixedbugs/issue5089.go @@ -0,0 +1,15 @@ +// 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. + +// issue 5089: gc allows methods on non-locals if symbol already exists + +package p + +import "bufio" + +func (b *bufio.Reader) Buffered() int { // ERROR "non-local" + return -1 +} diff --git a/test/fixedbugs/issue5105.dir/a.go b/test/fixedbugs/issue5105.dir/a.go new file mode 100644 index 000000000..f20abb98b --- /dev/null +++ b/test/fixedbugs/issue5105.dir/a.go @@ -0,0 +1,7 @@ +// 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 + +var A = [2]string{"hello", "world"} diff --git a/test/fixedbugs/issue5105.dir/b.go b/test/fixedbugs/issue5105.dir/b.go new file mode 100644 index 000000000..b12e739e3 --- /dev/null +++ b/test/fixedbugs/issue5105.dir/b.go @@ -0,0 +1,15 @@ +// 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" + +var B = [2]string{"world", "hello"} + +func main() { + if a.A[0] != B[1] { + panic("bad hello") + } +} diff --git a/test/fixedbugs/issue5105.go b/test/fixedbugs/issue5105.go new file mode 100644 index 000000000..e3e5e5caa --- /dev/null +++ b/test/fixedbugs/issue5105.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 5105: linker segfaults on duplicate definition +// of a type..hash.* function. + +package ignored diff --git a/test/fixedbugs/issue5125.dir/bug.go b/test/fixedbugs/issue5125.dir/bug.go new file mode 100644 index 000000000..2fdf0f9bb --- /dev/null +++ b/test/fixedbugs/issue5125.dir/bug.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 bug + +type Node interface { + Eval(s *Scene) +} + +type plug struct { + node Node +} + +type Scene struct { + changed map[plug]bool +} diff --git a/test/fixedbugs/issue5125.dir/main.go b/test/fixedbugs/issue5125.dir/main.go new file mode 100644 index 000000000..47acdeba8 --- /dev/null +++ b/test/fixedbugs/issue5125.dir/main.go @@ -0,0 +1,10 @@ +// 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 _ "./bug" + +func main() { +} diff --git a/test/fixedbugs/issue5125.go b/test/fixedbugs/issue5125.go new file mode 100644 index 000000000..c049df3e2 --- /dev/null +++ b/test/fixedbugs/issue5125.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 5125: cyclic dependencies between types confuse +// the hashability test during import. + +package ignored diff --git a/test/fixedbugs/issue5162.go b/test/fixedbugs/issue5162.go new file mode 100644 index 000000000..b14eae786 --- /dev/null +++ b/test/fixedbugs/issue5162.go @@ -0,0 +1,88 @@ +// runoutput + +// 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 5162: bad array equality when multiple comparisons +// happen in the same expression. + +package main + +import ( + "fmt" + "strings" +) + +const template = ` +func CheckEqNNN_TTT() { + onesA := [NNN]ttt{ONES} + onesB := [NNN]ttt{ONES} + twos := [NNN]ttt{TWOS} + if onesA != onesB { + println("onesA != onesB in CheckEqNNN_TTT") + } + if onesA == twos { + println("onesA == twos in CheckEqNNN_TTT") + } + if onesB == twos { + println("onesB == twos in CheckEqNNN_TTT") + } + if s := fmt.Sprint(onesA == onesB, onesA != twos, onesB != twos); s != "true true true" { + println("fail in CheckEqNNN_TTT:", s) + } +} + +func CheckEqNNN_TTTExtraVar() { + onesA := [NNN]ttt{ONES} + onesB := [NNN]ttt{ONES} + twos := [NNN]ttt{TWOS} + onesX := onesA + if onesA != onesB { + println("onesA != onesB in CheckEqNNN_TTTExtraVar") + } + if onesA == twos { + println("onesA == twos in CheckEqNNN_TTTExtraVar") + } + if onesB == twos { + println("onesB == twos in CheckEqNNN_TTTExtraVar") + } + if s := fmt.Sprint(onesA == onesB, onesA != twos, onesB != twos); s != "true true true" { + println("fail in CheckEqNNN_TTTExtraVar:", s) + } + if s := fmt.Sprint(onesB == onesX); s != "true" { + println("extra var fail in CheckEqNNN_TTTExtraVar") + } +} +` + +func main() { + fmt.Print("// run\n\n") + fmt.Print("// THIS FILE IS AUTO-GENERATED\n\n") + fmt.Print("package main\n\n") + fmt.Println(`import "fmt"`) + + types := []string{ + "int", "int8", "int16", "int32", "int64", + "uint", "uint8", "uint16", "uint32", "uint64", + "float32", "float64"} + tocall := make([]string, 0, 32*len(types)) + for i := 1; i <= 32; i++ { + for _, typ := range types { + src := template + src = strings.Replace(src, "NNN", fmt.Sprint(i), -1) + src = strings.Replace(src, "TTT", strings.Title(typ), -1) + src = strings.Replace(src, "ttt", typ, -1) + src = strings.Replace(src, "ONES", "1"+strings.Repeat(", 1", i-1), -1) + src = strings.Replace(src, "TWOS", "2"+strings.Repeat(", 2", i-1), -1) + fmt.Print(src) + tocall = append(tocall, fmt.Sprintf("CheckEq%d_%s", i, strings.Title(typ))) + } + } + fmt.Println("func main() {") + for _, fun := range tocall { + fmt.Printf("\t%s()\n", fun) + fmt.Printf("\t%sExtraVar()\n", fun) + } + fmt.Println("}") +} diff --git a/test/fixedbugs/issue5231.go b/test/fixedbugs/issue5231.go new file mode 100644 index 000000000..4039913dc --- /dev/null +++ b/test/fixedbugs/issue5231.go @@ -0,0 +1,45 @@ +// 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. + +// Issue 5231: method values lose their variadic property. + +package p + +type T int + +func (t T) NotVariadic(s []int) int { + return int(t) + s[0] +} + +func (t T) Variadic(s ...int) int { + return int(t) + s[0] +} + +type I interface { + NotVariadic(s []int) int + Variadic(s ...int) int +} + +func F() { + var t T + var p *T = &t + var i I = p + + nv := t.NotVariadic + nv = p.NotVariadic + nv = i.NotVariadic + var s int = nv([]int{1, 2, 3}) + + v := t.Variadic + v = p.Variadic + v = i.Variadic + s = v(1, 2, 3) + + var f1 func([]int) int = nv + var f2 func(...int) int = v + + _, _, _ = f1, f2, s +} diff --git a/test/fixedbugs/issue5259.dir/bug.go b/test/fixedbugs/issue5259.dir/bug.go new file mode 100644 index 000000000..851246168 --- /dev/null +++ b/test/fixedbugs/issue5259.dir/bug.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 bug + +type S struct { + F func() +} + +type X interface { + Bar() +} + +func Foo(x X) *S { + return &S{F: x.Bar} +} diff --git a/test/fixedbugs/issue5259.dir/main.go b/test/fixedbugs/issue5259.dir/main.go new file mode 100644 index 000000000..ad1da78f5 --- /dev/null +++ b/test/fixedbugs/issue5259.dir/main.go @@ -0,0 +1,16 @@ +// 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 "./bug" + +type foo int + +func (f *foo) Bar() { +} + +func main() { + bug.Foo(new(foo)) +} diff --git a/test/fixedbugs/issue5259.go b/test/fixedbugs/issue5259.go new file mode 100644 index 000000000..00fe19ff9 --- /dev/null +++ b/test/fixedbugs/issue5259.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. + +// Issue 5259: Inlining of method value causes internal compiler error + +package ignored diff --git a/test/fixedbugs/issue5260.dir/a.go b/test/fixedbugs/issue5260.dir/a.go new file mode 100644 index 000000000..5a2c99f65 --- /dev/null +++ b/test/fixedbugs/issue5260.dir/a.go @@ -0,0 +1,7 @@ +// 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 + +const BOM = "\uFEFF" diff --git a/test/fixedbugs/issue5260.dir/b.go b/test/fixedbugs/issue5260.dir/b.go new file mode 100644 index 000000000..299b75e4a --- /dev/null +++ b/test/fixedbugs/issue5260.dir/b.go @@ -0,0 +1,11 @@ +// 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" + +func main() { + _ = a.BOM +} diff --git a/test/fixedbugs/issue5260.go b/test/fixedbugs/issue5260.go new file mode 100644 index 000000000..11fd5d048 --- /dev/null +++ b/test/fixedbugs/issue5260.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 5260: Unicode BOM in exported string constant +// cannot be read back during package import. + +package ignored diff --git a/test/fixedbugs/issue5291.dir/pkg1.go b/test/fixedbugs/issue5291.dir/pkg1.go new file mode 100644 index 000000000..b1c893ac8 --- /dev/null +++ b/test/fixedbugs/issue5291.dir/pkg1.go @@ -0,0 +1,34 @@ +// 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 pkg1 + +import ( + "runtime" +) + +type T2 *[]string + +type Data struct { + T1 *[]T2 +} + +func CrashCall() (err error) { + var d Data + + for count := 0; count < 10; count++ { + runtime.GC() + + len := 2 // crash when >=2 + x := make([]T2, len) + + d = Data{T1: &x} + + for j := 0; j < len; j++ { + y := make([]string, 1) + (*d.T1)[j] = &y + } + } + return nil +} diff --git a/test/fixedbugs/issue5291.dir/prog.go b/test/fixedbugs/issue5291.dir/prog.go new file mode 100644 index 000000000..8301091bd --- /dev/null +++ b/test/fixedbugs/issue5291.dir/prog.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 main + +import ( + "./pkg1" +) + +type message struct { // Presence of this creates a crash + data pkg1.Data +} + +func main() { + pkg1.CrashCall() +} diff --git a/test/fixedbugs/issue5291.go b/test/fixedbugs/issue5291.go new file mode 100644 index 000000000..00d2ada4c --- /dev/null +++ b/test/fixedbugs/issue5291.go @@ -0,0 +1,9 @@ +// 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 5291: GC crash + +package ignored |