diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /test/fixedbugs | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'test/fixedbugs')
206 files changed, 4220 insertions, 231 deletions
diff --git a/test/fixedbugs/bug083.go b/test/fixedbugs/bug083.go index 984969d47..54a17423a 100644 --- a/test/fixedbugs/bug083.go +++ b/test/fixedbugs/bug083.go @@ -1,7 +1,7 @@ -// $G $D/$F.dir/bug0.go && errchk $G $D/$F.dir/bug1.go +// errorcheckdir // Copyright 2009 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. -ignored +package ignored diff --git a/test/fixedbugs/bug085.go b/test/fixedbugs/bug085.go index 93ae7e0a4..dae83f8a4 100644 --- a/test/fixedbugs/bug085.go +++ b/test/fixedbugs/bug085.go @@ -20,7 +20,7 @@ Bus error /* expected scope hierarchy (outermost to innermost) -universe scope (contains predeclared identifiers int, float, int32, len, etc.) +universe scope (contains predeclared identifiers int, float32, int32, len, etc.) "solar" scope (just holds the package name P so it can be found but doesn't conflict) global scope (the package global scope) local scopes (function scopes) diff --git a/test/fixedbugs/bug088.go b/test/fixedbugs/bug088.go index 9715a703c..3b99da84d 100644 --- a/test/fixedbugs/bug088.go +++ b/test/fixedbugs/bug088.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/bug0.go && $G $D/$F.dir/bug1.go || echo BUG: fails incorrectly +// compiledir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug106.go b/test/fixedbugs/bug106.go index 1874b2044..3b99da84d 100644 --- a/test/fixedbugs/bug106.go +++ b/test/fixedbugs/bug106.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/bug0.go && $G $D/$F.dir/bug1.go || echo BUG: failed to compile +// compiledir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug133.go b/test/fixedbugs/bug133.go index 2beeb074f..54a17423a 100644 --- a/test/fixedbugs/bug133.go +++ b/test/fixedbugs/bug133.go @@ -1,7 +1,7 @@ -// $G $D/$F.dir/bug0.go && $G $D/$F.dir/bug1.go && errchk $G $D/$F.dir/bug2.go +// errorcheckdir // Copyright 2009 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. -ignored +package ignored diff --git a/test/fixedbugs/bug160.go b/test/fixedbugs/bug160.go index 8fd53ea07..fde797bfc 100644 --- a/test/fixedbugs/bug160.go +++ b/test/fixedbugs/bug160.go @@ -1,7 +1,7 @@ -// $G $D/bug160.dir/x.go && $G $D/bug160.dir/y.go && $L y.$A && ./$A.out +// rundir // Copyright 2009 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. -nothing to see here +package ignored diff --git a/test/fixedbugs/bug191.dir/main.go b/test/fixedbugs/bug191.dir/main.go new file mode 100644 index 000000000..995134ccf --- /dev/null +++ b/test/fixedbugs/bug191.dir/main.go @@ -0,0 +1,14 @@ +// Copyright 2009 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" +import . "./b" + +var _ T +var _ V + +func main() { +} diff --git a/test/fixedbugs/bug191.go b/test/fixedbugs/bug191.go index 44fcccfc0..acb4796b3 100644 --- a/test/fixedbugs/bug191.go +++ b/test/fixedbugs/bug191.go @@ -1,16 +1,9 @@ -// $G $D/bug191.dir/a.go && $G $D/bug191.dir/b.go && $G $D/$F.go && $L $F.$A +// rundircmpout // Copyright 2009 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 +// Tests bug with dot imports. -import . "./a" -import . "./b" - -var _ T -var _ V - -func main() { -} +package ignored diff --git a/test/fixedbugs/bug191.out b/test/fixedbugs/bug191.out new file mode 100644 index 000000000..0e1677a97 --- /dev/null +++ b/test/fixedbugs/bug191.out @@ -0,0 +1,2 @@ +b +a diff --git a/test/fixedbugs/bug205.go b/test/fixedbugs/bug205.go index de17cb698..769837d04 100644 --- a/test/fixedbugs/bug205.go +++ b/test/fixedbugs/bug205.go @@ -11,8 +11,8 @@ var s string; var m map[string]int; func main() { - println(t["hi"]); // ERROR "integer" - println(s["hi"]); // ERROR "integer" "to type uint" - println(m[0]); // ERROR "map index" + println(t["hi"]); // ERROR "non-integer slice index" + println(s["hi"]); // ERROR "non-integer string index" + println(m[0]); // ERROR "as type string in map index" } diff --git a/test/fixedbugs/bug206.go b/test/fixedbugs/bug206.go index 7efc0b14a..c2382acf1 100644 --- a/test/fixedbugs/bug206.go +++ b/test/fixedbugs/bug206.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out >/dev/null 2>&1 || echo BUG: bug206 +// cmpout // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug206.out b/test/fixedbugs/bug206.out new file mode 100644 index 000000000..aa47d0d46 --- /dev/null +++ b/test/fixedbugs/bug206.out @@ -0,0 +1,2 @@ +0 +0 diff --git a/test/fixedbugs/bug222.go b/test/fixedbugs/bug222.go index 5c23a533d..3b99da84d 100644 --- a/test/fixedbugs/bug222.go +++ b/test/fixedbugs/bug222.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/chanbug.go && $G -I. $D/$F.dir/chanbug2.go +// compiledir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug223.go b/test/fixedbugs/bug223.go index eccf574a1..29ae53cb7 100644 --- a/test/fixedbugs/bug223.go +++ b/test/fixedbugs/bug223.go @@ -18,4 +18,4 @@ func f() { } } -var m = map[string]F{"f": f} // ERROR "initialization loop" +var m = map[string]F{"f": f} // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/bug228.go b/test/fixedbugs/bug228.go index 3d23609dd..3fccd1728 100644 --- a/test/fixedbugs/bug228.go +++ b/test/fixedbugs/bug228.go @@ -8,11 +8,11 @@ package main func f(x int, y ...int) // ok -func g(x int, y float) (...) // ERROR "[.][.][.]" "final argument" +func g(x int, y float32) (...) // ERROR "[.][.][.]" "final argument" func h(x, y ...int) // ERROR "[.][.][.]" -func i(x int, y ...int, z float) // ERROR "[.][.][.]" +func i(x int, y ...int, z float32) // ERROR "[.][.][.]" var x ...int; // ERROR "[.][.][.]|syntax|type" diff --git a/test/fixedbugs/bug248.go b/test/fixedbugs/bug248.go index 055bf1fd7..98cda35c4 100644 --- a/test/fixedbugs/bug248.go +++ b/test/fixedbugs/bug248.go @@ -5,6 +5,9 @@ // $L bug2.$A && // ./$A.out || echo BUG: failed to compile +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + // Copyright 2009 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. diff --git a/test/fixedbugs/bug255.go b/test/fixedbugs/bug255.go index dbd41cc6a..acf4f2391 100644 --- a/test/fixedbugs/bug255.go +++ b/test/fixedbugs/bug255.go @@ -12,4 +12,4 @@ 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 "overflows" +var g [1<<65]int // ERROR "array bound is too large|overflows" diff --git a/test/fixedbugs/bug273.go b/test/fixedbugs/bug273.go index b35b17d2e..aabb912b9 100644 --- a/test/fixedbugs/bug273.go +++ b/test/fixedbugs/bug273.go @@ -8,14 +8,15 @@ package main -import "unsafe" - var bug = false var minus1 = -1 +var five = 5 var big int64 = 10 | 1<<32 -var g1 []int +type block [1<<19]byte + +var g1 []block func shouldfail(f func(), desc string) { defer func() { recover() }() @@ -28,55 +29,47 @@ func shouldfail(f func(), desc string) { } func badlen() { - g1 = make([]int, minus1) + g1 = make([]block, minus1) } func biglen() { - g1 = make([]int, big) + g1 = make([]block, big) } func badcap() { - g1 = make([]int, 10, minus1) + g1 = make([]block, 10, minus1) } func badcap1() { - g1 = make([]int, 10, 5) + g1 = make([]block, 10, five) } func bigcap() { - g1 = make([]int, 10, big) + g1 = make([]block, 10, big) } -var g3 map[int]int +var g3 map[block]block func badmapcap() { - g3 = make(map[int]int, minus1) + g3 = make(map[block]block, minus1) } func bigmapcap() { - g3 = make(map[int]int, big) + g3 = make(map[block]block, big) } -var g4 chan int +type cblock [1<<16-1]byte + +var g4 chan cblock func badchancap() { - g4 = make(chan int, minus1) + g4 = make(chan cblock, minus1) } func bigchancap() { - g4 = make(chan int, big) + g4 = make(chan cblock, big) } -const addrBits = unsafe.Sizeof((*byte)(nil)) - -var g5 chan [1<<15]byte func overflowchan() { - if addrBits == 32 { - g5 = make(chan [1<<15]byte, 1<<20) - } else { - // cannot overflow on 64-bit, because - // int is 32 bits and max chan value size - // in the implementation is 64 kB. - panic(1) - } + g4 = make(chan cblock, 1<<30) } func main() { diff --git a/test/fixedbugs/bug282.go b/test/fixedbugs/bug282.go index 463f21e94..3b99da84d 100644 --- a/test/fixedbugs/bug282.go +++ b/test/fixedbugs/bug282.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/p1.go && $G $D/$F.dir/p2.go +// compiledir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug297.go b/test/fixedbugs/bug297.go index b5dfa8d87..ee2ff9243 100644 --- a/test/fixedbugs/bug297.go +++ b/test/fixedbugs/bug297.go @@ -11,5 +11,5 @@ package main type ByteSize float64 const ( _ = iota; // ignore first value by assigning to blank identifier - KB ByteSize = 1<<(10*X) // ERROR "undefined" "as type ByteSize" + KB ByteSize = 1<<(10*X) // ERROR "undefined" "is not a constant|as type ByteSize" ) diff --git a/test/fixedbugs/bug302.go b/test/fixedbugs/bug302.go index 1088b2f3c..dc7637fe5 100644 --- a/test/fixedbugs/bug302.go +++ b/test/fixedbugs/bug302.go @@ -1,5 +1,8 @@ // $G $D/bug302.dir/p.go && pack grc pp.a p.$A && $G $D/bug302.dir/main.go +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + // Copyright 2010 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. diff --git a/test/fixedbugs/bug306.go b/test/fixedbugs/bug306.go index a0a43507d..e8967c25d 100644 --- a/test/fixedbugs/bug306.go +++ b/test/fixedbugs/bug306.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/p1.go && $G $D/$F.dir/p2.go +// compiledir // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug313.go b/test/fixedbugs/bug313.go index eb2a0223b..a7c1d3627 100644 --- a/test/fixedbugs/bug313.go +++ b/test/fixedbugs/bug313.go @@ -1,4 +1,4 @@ -// errchk $G -e $D/$F.dir/[ab].go +// errorcheckdir // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug322.go b/test/fixedbugs/bug322.go index ad0e62dc8..21efbb559 100644 --- a/test/fixedbugs/bug322.go +++ b/test/fixedbugs/bug322.go @@ -1,8 +1,8 @@ -// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: fails incorrectly +// rundir // Copyright 2011 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 case for issue 1402. -ignored +package ignored diff --git a/test/fixedbugs/bug324.dir/main.go b/test/fixedbugs/bug324.dir/prog.go index 3ab61f3eb..3ab61f3eb 100644 --- a/test/fixedbugs/bug324.dir/main.go +++ b/test/fixedbugs/bug324.dir/prog.go diff --git a/test/fixedbugs/bug324.go b/test/fixedbugs/bug324.go index 3da75630a..36b8b56d1 100644 --- a/test/fixedbugs/bug324.go +++ b/test/fixedbugs/bug324.go @@ -1,8 +1,10 @@ -// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out +// rundir // Copyright 2011 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 case for issue 1550 -ignored +// Test case for issue 1550: a type cannot implement an interface +// from another package with a private method, and type assertions +// should fail. +package ignored diff --git a/test/fixedbugs/bug335.dir/a.go b/test/fixedbugs/bug335.dir/a.go index 5a8112a9d..256c110d7 100644 --- a/test/fixedbugs/bug335.dir/a.go +++ b/test/fixedbugs/bug335.dir/a.go @@ -4,6 +4,8 @@ package a -import "./b" +type T interface{} -var Bar = b.Foo +func f() T { return nil } + +var Foo T = f() diff --git a/test/fixedbugs/bug335.dir/b.go b/test/fixedbugs/bug335.dir/b.go index 7428c2a91..1474470d4 100644 --- a/test/fixedbugs/bug335.dir/b.go +++ b/test/fixedbugs/bug335.dir/b.go @@ -4,8 +4,6 @@ package b -type T interface{} +import "./a" -func f() T { return nil } - -var Foo T = f() +var Bar = a.Foo diff --git a/test/fixedbugs/bug335.go b/test/fixedbugs/bug335.go index 915b74657..37c97d7b5 100644 --- a/test/fixedbugs/bug335.go +++ b/test/fixedbugs/bug335.go @@ -1,5 +1,4 @@ -// $G $D/$F.dir/b.go && $G $D/$F.dir/a.go -// rm -f a.$A b.$A +// compiledir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -7,4 +6,4 @@ // Issue 1705. -unused (see script at top of file) +package ignored diff --git a/test/fixedbugs/bug345.go b/test/fixedbugs/bug345.go index 874710ce8..e3705f6c1 100644 --- a/test/fixedbugs/bug345.go +++ b/test/fixedbugs/bug345.go @@ -1,5 +1,8 @@ // $G $D/$F.dir/io.go && errchk $G -e $D/$F.dir/main.go +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + // Copyright 2011 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. diff --git a/test/fixedbugs/bug357.go b/test/fixedbugs/bug357.go index 2ac64a80b..ceb2009be 100644 --- a/test/fixedbugs/bug357.go +++ b/test/fixedbugs/bug357.go @@ -15,7 +15,7 @@ func bla1() bool { func bla5() bool { _ = 1 - false // ERROR "false not used|value computed is not used" + false // ERROR "false evaluated but not used|value computed is not used" _ = 2 return false } diff --git a/test/fixedbugs/bug358.go b/test/fixedbugs/bug358.go index 6a008484f..063c2e0bf 100644 --- a/test/fixedbugs/bug358.go +++ b/test/fixedbugs/bug358.go @@ -12,7 +12,7 @@ package main import ( "io/ioutil" // GCCGO_ERROR "imported and not used" "net/http" - "os" + "os" // GCCGO_ERROR "imported and not used" ) func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc { diff --git a/test/fixedbugs/bug367.dir/main.go b/test/fixedbugs/bug367.dir/prog.go index c278e4dd9..c278e4dd9 100644 --- a/test/fixedbugs/bug367.dir/main.go +++ b/test/fixedbugs/bug367.dir/prog.go diff --git a/test/fixedbugs/bug367.go b/test/fixedbugs/bug367.go index 25d11a153..05252cd9a 100644 --- a/test/fixedbugs/bug367.go +++ b/test/fixedbugs/bug367.go @@ -1,7 +1,10 @@ -// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: should not fail +// rundir // Copyright 2011 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 1536: bug when handling imported interfaces with +// private methods. + package ignored diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go index 4d98e8508..6d526228b 100644 --- a/test/fixedbugs/bug369.go +++ b/test/fixedbugs/bug369.go @@ -2,6 +2,9 @@ // $G -o fast.$A $D/bug369.dir/pkg.go && // run +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + // Copyright 2011 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. @@ -35,9 +38,9 @@ func BenchmarkSlowNonASCII(b *testing.B) { } func main() { - os.Args = []string{os.Args[0], "-test.benchtime=0.1"} + os.Args = []string{os.Args[0], "-test.benchtime=100ms"} flag.Parse() - + rslow := testing.Benchmark(BenchmarkSlowNonASCII) rfast := testing.Benchmark(BenchmarkFastNonASCII) tslow := rslow.NsPerOp() diff --git a/test/fixedbugs/bug377.go b/test/fixedbugs/bug377.go index e905e34d6..22df005b2 100644 --- a/test/fixedbugs/bug377.go +++ b/test/fixedbugs/bug377.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go +// compiledir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug379.go b/test/fixedbugs/bug379.go index 81e9c266e..14abe469b 100644 --- a/test/fixedbugs/bug379.go +++ b/test/fixedbugs/bug379.go @@ -14,5 +14,5 @@ package main func main() { - 1 + 2 // ERROR "1 \+ 2 not used|value computed is not used" + 1 + 2 // ERROR "1 \+ 2 evaluated but not used|value computed is not used" } diff --git a/test/fixedbugs/bug382.dir/prog.go b/test/fixedbugs/bug382.dir/prog.go new file mode 100644 index 000000000..b74a82d82 --- /dev/null +++ b/test/fixedbugs/bug382.dir/prog.go @@ -0,0 +1,13 @@ +// Copyright 2011 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 2529 + +package main + +import "./pkg" + +var x = pkg.E + +var fo = struct{ F pkg.T }{F: x} diff --git a/test/fixedbugs/bug382.go b/test/fixedbugs/bug382.go index 3f5d05cd5..6039939ee 100644 --- a/test/fixedbugs/bug382.go +++ b/test/fixedbugs/bug382.go @@ -1,14 +1,9 @@ -// $G $D/$F.dir/pkg.go && $G $D/$F.go || echo "Bug 382" +// compiledir // Copyright 2011 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 2529 +// Issue 2529. -package main -import "./pkg" - -var x = pkg.E - -var fo = struct {F pkg.T}{F: x} +package ignored diff --git a/test/fixedbugs/bug385_32.go b/test/fixedbugs/bug385_32.go index b9ecbb4c1..724ed9326 100644 --- a/test/fixedbugs/bug385_32.go +++ b/test/fixedbugs/bug385_32.go @@ -1,4 +1,5 @@ -// [ $A == 6 ] || errchk $G -e $D/$F.go +// +build 386 arm +// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -11,4 +12,4 @@ func main() { var arr [1000200030]int // ERROR "type .* too large" arr_bkup := arr _ = arr_bkup -}
\ No newline at end of file +} diff --git a/test/fixedbugs/bug385_64.go b/test/fixedbugs/bug385_64.go index 7476b17d5..b5621b210 100644 --- a/test/fixedbugs/bug385_64.go +++ b/test/fixedbugs/bug385_64.go @@ -1,15 +1,22 @@ -// [ $A != 6 ] || errchk $G -e $D/$F.go +// +build amd64 +// errorcheck // Copyright 2011 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 2444 +// Issue 4666: issue with arrays of exactly 4GB. package main -func main() { // ERROR "stack frame too large" - var arr [1000200030]int + +func main() { // ERROR "stack frame too large" + var arr [1000200030]int32 arr_bkup := arr _ = arr_bkup } +func F() { // ERROR "stack frame too large" + var arr [1 << 30]int32 + _ = arr[42] +} diff --git a/test/fixedbugs/bug392.dir/two.go b/test/fixedbugs/bug392.dir/pkg2.go index a9033dbb0..8320b2fff 100644 --- a/test/fixedbugs/bug392.dir/two.go +++ b/test/fixedbugs/bug392.dir/pkg2.go @@ -5,7 +5,7 @@ // Use the functions in one.go so that the inlined // forms get type-checked. -package two +package pkg2 import "./one" diff --git a/test/fixedbugs/bug392.dir/pkg3.go b/test/fixedbugs/bug392.dir/pkg3.go new file mode 100644 index 000000000..402c3b083 --- /dev/null +++ b/test/fixedbugs/bug392.dir/pkg3.go @@ -0,0 +1,13 @@ +// 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. + +// Use the functions in pkg2.go so that the inlined +// forms get type-checked. + +package pkg3 + +import "./pkg2" + +var x = pkg2.F() +var v = pkg2.V diff --git a/test/fixedbugs/bug392.go b/test/fixedbugs/bug392.go index a7a4216c4..48b79e01b 100644 --- a/test/fixedbugs/bug392.go +++ b/test/fixedbugs/bug392.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go && $G $D/$F.dir/three.go +// compiledir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug396.dir/one.go b/test/fixedbugs/bug396.dir/one.go index 7902a07d5..96a1dd7dc 100644 --- a/test/fixedbugs/bug396.dir/one.go +++ b/test/fixedbugs/bug396.dir/one.go @@ -4,6 +4,7 @@ package one +// Issue 2687 type T struct { int } func New(i int) T { return T{i} } diff --git a/test/fixedbugs/bug396.go b/test/fixedbugs/bug396.go index 50af6006f..48b79e01b 100644 --- a/test/fixedbugs/bug396.go +++ b/test/fixedbugs/bug396.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go +// compiledir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug404.go b/test/fixedbugs/bug404.go index ac9e575bb..481acda32 100644 --- a/test/fixedbugs/bug404.go +++ b/test/fixedbugs/bug404.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go +// compiledir // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug407.go b/test/fixedbugs/bug407.go index 50af6006f..48b79e01b 100644 --- a/test/fixedbugs/bug407.go +++ b/test/fixedbugs/bug407.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go +// compiledir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug410.go b/test/fixedbugs/bug410.go index 35ecbfc05..430ddcbb5 100644 --- a/test/fixedbugs/bug410.go +++ b/test/fixedbugs/bug410.go @@ -18,7 +18,7 @@ func zzz () { for s := range arr { x := make([]byte, 10) for i := 0; i < 100 ; i++ { - x[i] ^= k[i-arr[s].num%0] + x[i] ^= k[i-arr[s].num%3] } } } diff --git a/test/fixedbugs/bug412.go b/test/fixedbugs/bug412.go index 9148b68e7..8dd0a5fcc 100644 --- a/test/fixedbugs/bug412.go +++ b/test/fixedbugs/bug412.go @@ -7,10 +7,10 @@ package p type t struct { - x int // ERROR "duplicate field x" + x int // ERROR "duplicate field x|duplicate field name .x." x int } func f(t *t) int { - return t.x // ERROR "ambiguous selector t.x" + return t.x // GC_ERROR "ambiguous selector t.x" } diff --git a/test/fixedbugs/bug413.go b/test/fixedbugs/bug413.go index 41270d906..ba8046490 100644 --- a/test/fixedbugs/bug413.go +++ b/test/fixedbugs/bug413.go @@ -8,4 +8,4 @@ package p func f(i int) int { return i } -var i = func() int {a := f(i); return a}() // ERROR "initialization loop"
\ No newline at end of file +var i = func() int {a := f(i); return a}() // ERROR "initialization loop|depends upon itself" diff --git a/test/fixedbugs/bug414.dir/main.go b/test/fixedbugs/bug414.dir/main.go deleted file mode 100644 index 52001233c..000000000 --- a/test/fixedbugs/bug414.dir/main.go +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - - package main - - import "./p1" - - type MyObject struct { - p1.Fer - } - - func main() { - var b p1.Fer = &p1.Object{} - p1.PrintFer(b) - var c p1.Fer = &MyObject{b} - p1.PrintFer(c) - } diff --git a/test/fixedbugs/bug414.dir/p1.go b/test/fixedbugs/bug414.dir/p1.go index 7768818bf..246383484 100644 --- a/test/fixedbugs/bug414.dir/p1.go +++ b/test/fixedbugs/bug414.dir/p1.go @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - package p1 - - import "fmt" - - type Fer interface { - f() string - } - - type Object struct {} - - func (this *Object) f() string { - return "Object.f" - } - - func PrintFer(fer Fer) { - fmt.Sprintln(fer.f()) - } +package p1 + +import "fmt" + +type Fer interface { + f() string +} + +type Object struct{} + +func (this *Object) f() string { + return "Object.f" +} + +func PrintFer(fer Fer) { + fmt.Sprintln(fer.f()) +} diff --git a/test/fixedbugs/bug414.dir/prog.go b/test/fixedbugs/bug414.dir/prog.go new file mode 100644 index 000000000..f55d94696 --- /dev/null +++ b/test/fixedbugs/bug414.dir/prog.go @@ -0,0 +1,18 @@ +// 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. + +package main + +import "./p1" + +type MyObject struct { + p1.Fer +} + +func main() { + var b p1.Fer = &p1.Object{} + p1.PrintFer(b) + var c p1.Fer = &MyObject{b} + p1.PrintFer(c) +} diff --git a/test/fixedbugs/bug414.go b/test/fixedbugs/bug414.go index 8824b1a1e..35e19be38 100644 --- a/test/fixedbugs/bug414.go +++ b/test/fixedbugs/bug414.go @@ -1,7 +1,9 @@ -// $G $D/$F.dir/p1.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out +// rundir // 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 1743: test embedding of imported types with private methods. + package ignored diff --git a/test/fixedbugs/bug415.dir/main.go b/test/fixedbugs/bug415.dir/prog.go index b894453fc..b894453fc 100644 --- a/test/fixedbugs/bug415.dir/main.go +++ b/test/fixedbugs/bug415.dir/prog.go diff --git a/test/fixedbugs/bug415.go b/test/fixedbugs/bug415.go index fbf034218..8cd4c49f2 100644 --- a/test/fixedbugs/bug415.go +++ b/test/fixedbugs/bug415.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go +// compiledir // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/bug416.go b/test/fixedbugs/bug416.go index c12853842..1d24fa935 100644 --- a/test/fixedbugs/bug416.go +++ b/test/fixedbugs/bug416.go @@ -10,4 +10,4 @@ type T struct { X int } -func (t *T) X() {} // ERROR "type T has both field and method named X" +func (t *T) X() {} // ERROR "type T has both field and method named X|redeclares struct field name" diff --git a/test/fixedbugs/bug424.dir/main.go b/test/fixedbugs/bug424.dir/main.go new file mode 100644 index 000000000..c2fe1463c --- /dev/null +++ b/test/fixedbugs/bug424.dir/main.go @@ -0,0 +1,97 @@ +// 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. + +// Tests that method calls through an interface always +// call the locally defined method localT.m independent +// at which embedding level it is and in which order +// embedding is done. + +package main + +import "./lib" +import "reflect" +import "fmt" + +type localI interface { + m() string +} + +type localT struct{} + +func (t *localT) m() string { + return "main.localT.m" +} + +type myT1 struct { + localT +} + +type myT2 struct { + localT + lib.T +} + +type myT3 struct { + lib.T + localT +} + +func main() { + var i localI + + i = new(localT) + if i.m() != "main.localT.m" { + println("BUG: localT:", i.m(), "called") + } + + i = new(myT1) + if i.m() != "main.localT.m" { + println("BUG: myT1:", i.m(), "called") + } + + i = new(myT2) + if i.m() != "main.localT.m" { + println("BUG: myT2:", i.m(), "called") + } + + t3 := new(myT3) + if t3.m() != "main.localT.m" { + println("BUG: t3:", t3.m(), "called") + } + + i = new(myT3) + if i.m() != "main.localT.m" { + t := reflect.TypeOf(i) + n := t.NumMethod() + for j := 0; j < n; j++ { + m := t.Method(j) + fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type) + } + println("BUG: myT3:", i.m(), "called") + } + + var t4 struct { + localT + lib.T + } + if t4.m() != "main.localT.m" { + println("BUG: t4:", t4.m(), "called") + } + i = &t4 + if i.m() != "main.localT.m" { + println("BUG: myT4:", i.m(), "called") + } + + var t5 struct { + lib.T + localT + } + if t5.m() != "main.localT.m" { + println("BUG: t5:", t5.m(), "called") + } + i = &t5 + if i.m() != "main.localT.m" { + println("BUG: myT5:", i.m(), "called") + } +} diff --git a/test/fixedbugs/bug424.go b/test/fixedbugs/bug424.go index 42cff54d4..59c2cd35c 100644 --- a/test/fixedbugs/bug424.go +++ b/test/fixedbugs/bug424.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/lib.go && $G $D/$F.go && $L $F.$A && ./$A.out +// rundir // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -9,91 +9,5 @@ // at which embedding level it is and in which order // embedding is done. -package main +package ignored -import "./lib" -import "reflect" -import "fmt" - -type localI interface { - m() string -} - -type localT struct{} - -func (t *localT) m() string { - return "main.localT.m" -} - -type myT1 struct { - localT -} - -type myT2 struct { - localT - lib.T -} - -type myT3 struct { - lib.T - localT -} - -func main() { - var i localI - - i = new(localT) - if i.m() != "main.localT.m" { - println("BUG: localT:", i.m(), "called") - } - - i = new(myT1) - if i.m() != "main.localT.m" { - println("BUG: myT1:", i.m(), "called") - } - - i = new(myT2) - if i.m() != "main.localT.m" { - println("BUG: myT2:", i.m(), "called") - } - - t3 := new(myT3) - if t3.m() != "main.localT.m" { - println("BUG: t3:", t3.m(), "called") - } - - i = new(myT3) - if i.m() != "main.localT.m" { - t := reflect.TypeOf(i) - n := t.NumMethod() - for j := 0; j < n; j++ { - m := t.Method(j) - fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type) - } - println("BUG: myT3:", i.m(), "called") - } - - var t4 struct { - localT - lib.T - } - if t4.m() != "main.localT.m" { - println("BUG: t4:", t4.m(), "called") - } - i = &t4 - if i.m() != "main.localT.m" { - println("BUG: myT4:", i.m(), "called") - } - - var t5 struct { - lib.T - localT - } - if t5.m() != "main.localT.m" { - println("BUG: t5:", t5.m(), "called") - } - i = &t5 - if i.m() != "main.localT.m" { - println("BUG: myT5:", i.m(), "called") - } -} diff --git a/test/fixedbugs/bug429.go b/test/fixedbugs/bug429.go index c1bd1d4bb..794d293db 100644 --- a/test/fixedbugs/bug429.go +++ b/test/fixedbugs/bug429.go @@ -1,5 +1,8 @@ // $G $D/$F.go && $L $F.$A && ! ./$A.out || echo BUG: bug429 +// NOTE: This test is not run by 'run.go' and so not run by all.bash. +// To run this test you must use the ./run shell script. + // 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. diff --git a/test/fixedbugs/bug430.go b/test/fixedbugs/bug430.go new file mode 100644 index 000000000..93d5cf2d5 --- /dev/null +++ b/test/fixedbugs/bug430.go @@ -0,0 +1,22 @@ +// 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. + +// gccgo crashed compiling this. + +package main + +type S struct { + f [2][]int +} + +func F() (r [2][]int) { + return +} + +func main() { + var a []S + a[0].f = F() +} diff --git a/test/fixedbugs/bug431.go b/test/fixedbugs/bug431.go new file mode 100644 index 000000000..1057dadcc --- /dev/null +++ b/test/fixedbugs/bug431.go @@ -0,0 +1,18 @@ +// 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. + +// gccgo gave an invalid error ("floating point constant truncated to +// integer") compiling this. + +package p + +const C = 1<<63 - 1 + +func F(i int64) int64 { + return i +} + +var V = F(int64(C) / 1e6) diff --git a/test/fixedbugs/bug432.go b/test/fixedbugs/bug432.go new file mode 100644 index 000000000..0c1a91461 --- /dev/null +++ b/test/fixedbugs/bug432.go @@ -0,0 +1,13 @@ +// 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. + +// gccgo crashed compiling this. + +package p + +var v struct{ I } + +type I interface{} diff --git a/test/fixedbugs/bug433.go b/test/fixedbugs/bug433.go new file mode 100644 index 000000000..1139dfa00 --- /dev/null +++ b/test/fixedbugs/bug433.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that initializing struct fields out of order still runs +// functions in the right order. This failed with gccgo. + +package main + +type S struct { + i1, i2, i3 int +} + +var G int + +func v(i int) int { + if i != G { + panic(i) + } + G = i + 1 + return G +} + +func F() S { + return S{ + i1: v(0), + i3: v(1), + i2: v(2), + } +} + +func main() { + s := F() + if s != (S{1, 3, 2}) { + panic(s) + } +} diff --git a/test/fixedbugs/bug434.go b/test/fixedbugs/bug434.go new file mode 100644 index 000000000..5abb567b4 --- /dev/null +++ b/test/fixedbugs/bug434.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that typed and untyped negative zero floating point constants +// are treated as equivalent to zero constants. + +package main + +import "math" + +const zero = 0.0 + +func main() { + x := -zero + b := math.Float64bits(x) + if b != 0 { + panic(b) + } + x = -float64(zero) + b = math.Float64bits(x) + if b != 0 { + panic(b) + } + v := x + b = math.Float64bits(-v) + if b != 0x8000000000000000 { + panic(b) + } +} diff --git a/test/fixedbugs/bug435.go b/test/fixedbugs/bug435.go new file mode 100644 index 000000000..9c30b143b --- /dev/null +++ b/test/fixedbugs/bug435.go @@ -0,0 +1,15 @@ +// errorcheck + +// 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. + +// Test that a syntax error caused by an unexpected EOF +// gives an error message with the correct line number. +// +// https://code.google.com/p/go/issues/detail?id=3392 + +package main + +func foo() { + bar(1, // ERROR "unexpected|missing|undefined" diff --git a/test/fixedbugs/bug436.go b/test/fixedbugs/bug436.go new file mode 100644 index 000000000..e848eaeba --- /dev/null +++ b/test/fixedbugs/bug436.go @@ -0,0 +1,32 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Gccgo used to crash compiling this. + +package main + +func foo() (int, int) { + return 1, 2 +} + +var c = b +var a, b = foo() +var d = b + 1 + +func main() { + if a != 1 { + panic(a) + } + if b != 2 { + panic(b) + } + if c != 2 { + panic(c) + } + if d != 3 { + panic(d) + } +} diff --git a/test/fixedbugs/bug437.dir/one.go b/test/fixedbugs/bug437.dir/one.go new file mode 100644 index 000000000..8d3caadae --- /dev/null +++ b/test/fixedbugs/bug437.dir/one.go @@ -0,0 +1,18 @@ +// 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. + +package one + +type I1 interface { + f() +} + +type S1 struct { +} + +func (s S1) f() { +} + +func F1(i1 I1) { +} diff --git a/test/fixedbugs/bug437.dir/two.go b/test/fixedbugs/bug437.dir/two.go new file mode 100644 index 000000000..406dd5903 --- /dev/null +++ b/test/fixedbugs/bug437.dir/two.go @@ -0,0 +1,11 @@ +// 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. + +package two + +import "./one" + +type S2 struct { + one.S1 +} diff --git a/test/fixedbugs/bug437.dir/x.go b/test/fixedbugs/bug437.dir/x.go new file mode 100644 index 000000000..364d017af --- /dev/null +++ b/test/fixedbugs/bug437.dir/x.go @@ -0,0 +1,25 @@ +// 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. + +// Test converting a type defined in a different package to an +// interface defined in a third package, where the interface has a +// hidden method. This used to cause a link error with gccgo. + +package main + +import ( + "./one" + "./two" +) + +func F(i1 one.I1) { + switch v := i1.(type) { + case two.S2: + one.F1(v) + } +} + +func main() { + F(nil) +} diff --git a/test/fixedbugs/bug437.go b/test/fixedbugs/bug437.go new file mode 100644 index 000000000..5c4a2ad0d --- /dev/null +++ b/test/fixedbugs/bug437.go @@ -0,0 +1,11 @@ +// rundir + +// 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. + +// Test converting a type defined in a different package to an +// interface defined in a third package, where the interface has a +// hidden method. This used to cause a link error with gccgo. + +package ignored diff --git a/test/fixedbugs/bug438.go b/test/fixedbugs/bug438.go new file mode 100644 index 000000000..15d3fdab8 --- /dev/null +++ b/test/fixedbugs/bug438.go @@ -0,0 +1,16 @@ +// 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. + +// Gccgo used to incorrectly give an error when compiling this. + +package p + +func F() (i int) { + for first := true; first; first = false { + i++ + } + return +} diff --git a/test/fixedbugs/bug439.go b/test/fixedbugs/bug439.go new file mode 100644 index 000000000..87d4ae037 --- /dev/null +++ b/test/fixedbugs/bug439.go @@ -0,0 +1,22 @@ +// 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. + +// Gccgo used to crash compiling this. + +package p + +type E int + +func (e E) P() *E { return &e } + +const ( + C1 E = 0 + C2 = C1 +) + +func F() *E { + return C2.P() +} diff --git a/test/fixedbugs/bug440_32.go b/test/fixedbugs/bug440_32.go new file mode 100644 index 000000000..2d26fbb90 --- /dev/null +++ b/test/fixedbugs/bug440_32.go @@ -0,0 +1,21 @@ +// run + +// Test for 8g register move bug. The optimizer gets confused +// about 16- vs 32-bit moves during splitContractIndex. + +// Issue 3910. + +package main + +func main() { + const c = 0x12345678 + index, n, offset := splitContractIndex(c) + if index != int((c&0xffff)>>5) || n != int(c&(1<<5-1)) || offset != (c>>16)&(1<<14-1) { + println("BUG", index, n, offset) + } +} + +func splitContractIndex(ce uint32) (index, n, offset int) { + h := uint16(ce) + return int(h >> 5), int(h & (1<<5 - 1)), int(ce>>16) & (1<<14 - 1) +} diff --git a/test/fixedbugs/bug440_64.go b/test/fixedbugs/bug440_64.go new file mode 100644 index 000000000..3ab3e565d --- /dev/null +++ b/test/fixedbugs/bug440_64.go @@ -0,0 +1,21 @@ +// run + +// Test for 6g register move bug. The optimizer gets confused +// about 32- vs 64-bit moves during splitContractIndex. + +// Issue 3918. + +package main + +func main() { + const c = 0x123400005678 + index, offset := splitContractIndex(c) + if index != (c&0xffffffff)>>5 || offset != c+1 { + println("BUG", index, offset) + } +} + +func splitContractIndex(ce uint64) (index uint32, offset uint64) { + h := uint32(ce) + return h >> 5, ce + 1 +} diff --git a/test/fixedbugs/bug444.go b/test/fixedbugs/bug444.go index 0bbd16fae..b54fb4f58 100644 --- a/test/fixedbugs/bug444.go +++ b/test/fixedbugs/bug444.go @@ -6,6 +6,7 @@ // The no-op conversion here used to confuse the compiler // into doing a load-effective-address of nil. +// See issue 3670. package main @@ -13,7 +14,23 @@ import "reflect" type T interface {} +var x bool + func main() { reflect.TypeOf(nil) - reflect.TypeOf(T(nil)) // used to fail + reflect.TypeOf(T(nil)) // used to miscompile + shouldPanic() +} + +func f() byte { + return []byte(nil)[0] // used to miscompile +} + +func shouldPanic() { + defer func() { + if recover() == nil { + panic("not panicking") + } + }() + f() } diff --git a/test/fixedbugs/bug445.go b/test/fixedbugs/bug445.go new file mode 100644 index 000000000..497ecd3ab --- /dev/null +++ b/test/fixedbugs/bug445.go @@ -0,0 +1,14 @@ +// 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 3765 + +package main + +func f(x uint) uint { + m := ^(1 << x) + return uint(m) +} diff --git a/test/fixedbugs/bug446.go b/test/fixedbugs/bug446.go new file mode 100644 index 000000000..1e435e110 --- /dev/null +++ b/test/fixedbugs/bug446.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 3824. +// Method calls are ignored when deciding initialization +// order. + +package main + +type T int + +func (r T) Method1() int { return a } +func (r T) Method2() int { return b } + +// dummy1 and dummy2 must be initialized after a and b. +var dummy1 = T(0).Method1() +var dummy2 = T.Method2(0) + +// Use a function call to force generating code. +var a = identity(1) +var b = identity(2) + +func identity(a int) int { return a } + +func main() { + if dummy1 != 1 { + panic("dummy1 != 1") + } + if dummy2 != 2 { + panic("dummy2 != 2") + } +} + diff --git a/test/fixedbugs/bug447.go b/test/fixedbugs/bug447.go new file mode 100644 index 000000000..a4c871bdb --- /dev/null +++ b/test/fixedbugs/bug447.go @@ -0,0 +1,105 @@ +// runoutput + +// 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 3804 +// test all possible float -> integer conversions + +package main + +import ( + "bytes" + "fmt" + "strings" +) + +var ( + intWidths = []int{8, 16, 32, 64} // int%d and uint%d + floatWidths = []int{32, 64} // float%d +) + +func main() { + + var names, funcs bytes.Buffer + + for _, iWidth := range intWidths { + for _, typ := range []string{"int", "uint"} { + var segs bytes.Buffer + itype := fmt.Sprintf("%s%d", typ, iWidth) + names.WriteString("\ttest" + itype + ",\n") + for _, fWidth := range floatWidths { + ftype := fmt.Sprintf("float%d", fWidth) + seg := strings.Replace(testSegment, "$F", ftype, -1) + seg = strings.Replace(seg, "$I", itype, -1) + segs.WriteString(seg) + } + body := strings.Replace(testFunc, "$I", itype, -1) + if typ[0] == 'u' { + body = strings.Replace(body, "$TEST", " || i < 0", 1) + } else { + body = strings.Replace(body, "$TEST", "", 1) + } + body = strings.Replace(body, "$TESTSEGMENTS", segs.String(), 1) + funcs.WriteString(body) + } + } + + program = strings.Replace(program, "$NAMES", names.String(), 1) + program = strings.Replace(program, "$FUNCS", funcs.String(), 1) + fmt.Print(program) +} + +const testSegment = ` + f$F := $F(f) + if math.Abs(float64(f$F) - f) < 0.05 { + if v := $I(f$F); v != $I(i) { + fmt.Printf("$I($F(%f)) = %v, expected %v\n", f, v, i) + } + }` + +const testFunc = +`func test$I(f float64, i int64) { + if i != int64($I(i))$TEST { + return + } +$TESTSEGMENTS +} +` + +var program = +`package main + +import ( + "fmt" + "math" +) + +var tests = []struct { + f float64 + i int64 +}{ + {39.7, 39}, + {-39.7, -39}, + {258.6, 258}, + {-258.6, -258}, + {65538.9, 65538}, + {-65538.9, -65538}, + {4294967298.8, 4294967298}, + {-4294967298.8, -4294967298}, +} + +var funcs = []func(float64, int64){ +$NAMES +} + +$FUNCS +func main() { + for _, t := range tests { + for _, f := range funcs { + f(t.f, t.i) + } + } +} +` diff --git a/test/fixedbugs/bug448.dir/pkg1.go b/test/fixedbugs/bug448.dir/pkg1.go new file mode 100644 index 000000000..032e5d9de --- /dev/null +++ b/test/fixedbugs/bug448.dir/pkg1.go @@ -0,0 +1,11 @@ +// 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. + +package pkg1 + +var x = make(chan interface{}) + +func Do() int { + return (<-x).(int) +} diff --git a/test/fixedbugs/bug448.dir/pkg2.go b/test/fixedbugs/bug448.dir/pkg2.go new file mode 100644 index 000000000..5c78c7d2f --- /dev/null +++ b/test/fixedbugs/bug448.dir/pkg2.go @@ -0,0 +1,14 @@ +// 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 3843: inlining bug due to wrong receive operator precedence. + +package pkg2 + +import "./pkg1" + +func F() { + pkg1.Do() +} + diff --git a/test/fixedbugs/bug448.go b/test/fixedbugs/bug448.go new file mode 100644 index 000000000..242f5999e --- /dev/null +++ b/test/fixedbugs/bug448.go @@ -0,0 +1,7 @@ +// compiledir + +// 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. + +package ignored diff --git a/test/fixedbugs/bug449.go b/test/fixedbugs/bug449.go new file mode 100644 index 000000000..a9650f4c6 --- /dev/null +++ b/test/fixedbugs/bug449.go @@ -0,0 +1,69 @@ +// runoutput + +// 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 3866 +// runtime.equal failed to take padding between arguments and +// return values into account, so in certain cases gc-generated +// code will read a random bool from the stack as the result of +// the comparison. +// This program generates a lot of equality tests and hopes to +// catch this. +// NOTE: this program assumes comparing instance of T and T's +// underlying []byte will make gc emit calls to runtime.equal, +// and if gc optimizes this case, then the test will no longer +// be correct (in the sense that it no longer tests runtime.equal). + +package main + +import ( + "bytes" + "fmt" + "strconv" + "strings" +) + +const ntest = 1024 + +func main() { + var decls, calls bytes.Buffer + + for i := 1; i <= ntest; i++ { + s := strconv.Itoa(i) + decls.WriteString(strings.Replace(decl, "$", s, -1)) + calls.WriteString(strings.Replace("call(test$)\n\t", "$", s, -1)) + } + + program = strings.Replace(program, "$DECLS", decls.String(), 1) + program = strings.Replace(program, "$CALLS", calls.String(), 1) + fmt.Print(program) +} + +var program = `package main + +var count int + +func call(f func() bool) { + if f() { + count++ + } +} + +$DECLS + +func main() { + $CALLS + if count != 0 { + println("failed", count, "case(s)") + } +} +` + +const decl = ` +type T$ [$]uint8 +func test$() bool { + v := T${1} + return v == [$]uint8{2} || v != [$]uint8{1} +}` diff --git a/test/fixedbugs/bug450.go b/test/fixedbugs/bug450.go new file mode 100644 index 000000000..3f13de16c --- /dev/null +++ b/test/fixedbugs/bug450.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 3899: 8g incorrectly thinks a variable is +// "set but not used" and elides an assignment, causing +// variables to end up with wrong data. +// +// The reason is a miscalculation of variable width. + +package main + +func bar(f func()) { + f() +} + +func foo() { + f := func() {} + if f == nil { + } + bar(f) +} + +func main() { + foo() +} diff --git a/test/fixedbugs/bug451.go b/test/fixedbugs/bug451.go new file mode 100644 index 000000000..75ce97490 --- /dev/null +++ b/test/fixedbugs/bug451.go @@ -0,0 +1,11 @@ +// errorcheck + +// 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. + +package main + +type T x.T // ERROR "undefined|expected package" + +// bogus "invalid recursive type" diff --git a/test/fixedbugs/bug452.go b/test/fixedbugs/bug452.go new file mode 100644 index 000000000..d2e4a0b44 --- /dev/null +++ b/test/fixedbugs/bug452.go @@ -0,0 +1,38 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 3835: 8g tries to optimize arithmetic involving integer +// constants, but can run out of registers in the process. + +package main + +var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G int + +func foo() int { + return a + 1 + b + 2 + c + 3 + d + 4 + e + 5 + f + 6 + g + 7 + h + 8 + i + 9 + j + 10 + + k + 1 + l + 2 + m + 3 + n + 4 + o + 5 + p + 6 + q + 7 + r + 8 + s + 9 + t + 10 + + u + 1 + v + 2 + w + 3 + x + 4 + y + 5 + z + 6 + A + 7 + B + 8 + C + 9 + D + 10 + + E + 1 + F + 2 + G + 3 +} + +func bar() int8 { + var ( + W int16 + X int32 + Y int32 + Z int32 + ) + return int8(W+int16(X+3)+3) * int8(Y+3+Z*3) +} + +func main() { + if foo() == 0 { + panic("foo") + } + if bar() == 0 { + panic("bar") + } +} diff --git a/test/fixedbugs/bug453.go b/test/fixedbugs/bug453.go new file mode 100644 index 000000000..136abefb7 --- /dev/null +++ b/test/fixedbugs/bug453.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4138: bug in floating-point registers numbering. +// Makes 6g unable to use more than 11 registers. + +package main + +func formula() float32 { + mA := [1]float32{1.0} + det1 := mA[0] + det2 := mA[0] + det3 := mA[0] + det4 := mA[0] + det5 := mA[0] + det6 := mA[0] + det7 := mA[0] + det8 := mA[0] + det9 := mA[0] + det10 := mA[0] + det11 := mA[0] + det12 := mA[0] + + return det1 + det2*det3 + + det4*det5 + det6*det7 + + det8*det9 + det10*det11 + + det12 +} + +func main() { + x := formula() + if x != 7.0 { + println(x, 7.0) + panic("x != 7.0") + } +} diff --git a/test/fixedbugs/bug454.go b/test/fixedbugs/bug454.go new file mode 100644 index 000000000..a10abba8b --- /dev/null +++ b/test/fixedbugs/bug454.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4173 + +package main + +func main() { + var arr *[10]int + s := 0 + for i, _ := range arr { + // used to panic trying to access arr[i] + s += i + } + if s != 45 { + println("BUG") + } +} diff --git a/test/fixedbugs/bug455.go b/test/fixedbugs/bug455.go new file mode 100644 index 000000000..8e3c7701b --- /dev/null +++ b/test/fixedbugs/bug455.go @@ -0,0 +1,54 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4156: out of fixed registers when chaining method calls. +// Used to happen with 6g. + +package main + +type test_i interface { + Test() test_i + Result() bool +} + +type test_t struct { +} + +func newTest() *test_t { + return &test_t{} +} + +type testFn func(string) testFn + +func main() { + test := newTest() + + switch { + case test. + Test(). + Test(). + Test(). + Test(). + Test(). + Test(). + Test(). + Test(). + Test(). + Test(). + Result(): + // case worked + default: + panic("Result returned false unexpectedly") + } +} + +func (t *test_t) Test() test_i { + return t +} + +func (t *test_t) Result() bool { + return true +} diff --git a/test/fixedbugs/bug456.go b/test/fixedbugs/bug456.go new file mode 100644 index 000000000..064e1aa02 --- /dev/null +++ b/test/fixedbugs/bug456.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 3907: out of fixed registers in nested byte multiply. +// Used to happen with both 6g and 8g. + +package main + +func F(a, b, c, d uint8) uint8 { + return a * (b * (c * (d * + (a * (b * (c * (d * + (a * (b * (c * (d * + a * (b * (c * d))))))))))))) +} + +func main() { + var a, b, c, d uint8 = 1, 1, 1, 1 + x := F(a, b, c, d) + if x != 1 { + println(x) + panic("x != 1") + } +} diff --git a/test/fixedbugs/bug457.go b/test/fixedbugs/bug457.go new file mode 100644 index 000000000..ee7048972 --- /dev/null +++ b/test/fixedbugs/bug457.go @@ -0,0 +1,15 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4197: growing a slice of zero-width elements +// panics on a division by zero. + +package main + +func main() { + var x []struct{} + x = append(x, struct{}{}) +} diff --git a/test/fixedbugs/bug458.go b/test/fixedbugs/bug458.go new file mode 100644 index 000000000..ddc97bdb0 --- /dev/null +++ b/test/fixedbugs/bug458.go @@ -0,0 +1,22 @@ +// 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 4200: 6g crashes when a type is larger than 4GB. + +package main + +import "unsafe" + +// N=16 on 32-bit arches, 256 on 64-bit arches. +// On 32-bit arches we don't want to test types +// that are over 4GB large. +const N = 1 << unsafe.Sizeof(uintptr(0)) + +type T [N][10][10][10][10][3]byte + +func F(t *T) byte { + return t[0][0][0][0][0][0] +} diff --git a/test/fixedbugs/bug459.go b/test/fixedbugs/bug459.go new file mode 100644 index 000000000..80abe5d51 --- /dev/null +++ b/test/fixedbugs/bug459.go @@ -0,0 +1,35 @@ +// errorcheck + +// 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 3890: missing detection of init loop involving +// method calls in function bodies. + +package flag + +var commandLine = NewFlagSet() // ERROR "loop" + +type FlagSet struct { +} + +func (f *FlagSet) failf(format string, a ...interface{}) { + f.usage() +} + +func (f *FlagSet) usage() { + if f == commandLine { + panic(3) + } +} + +func NewFlagSet() *FlagSet { + f := &FlagSet{} + f.setErrorHandling(true) + return f +} + +func (f *FlagSet) setErrorHandling(b bool) { + f.failf("DIE") +} diff --git a/test/fixedbugs/bug460.dir/a.go b/test/fixedbugs/bug460.dir/a.go new file mode 100644 index 000000000..02a287b31 --- /dev/null +++ b/test/fixedbugs/bug460.dir/a.go @@ -0,0 +1,9 @@ +// 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. + +package a + +type Foo struct { + int +} diff --git a/test/fixedbugs/bug460.dir/b.go b/test/fixedbugs/bug460.dir/b.go new file mode 100644 index 000000000..1868afe07 --- /dev/null +++ b/test/fixedbugs/bug460.dir/b.go @@ -0,0 +1,14 @@ +// 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. + +package b + +import "./a" + +var x a.Foo + +func main() { + x.int = 20 // ERROR "unexported field" +} + diff --git a/test/fixedbugs/bug460.go b/test/fixedbugs/bug460.go new file mode 100644 index 000000000..79234a3b9 --- /dev/null +++ b/test/fixedbugs/bug460.go @@ -0,0 +1,10 @@ +// errorcheckdir + +// 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. + +// part one of issue 4124. Make sure that the compiler rejects access attempts. + +package ignored + diff --git a/test/fixedbugs/bug461.go b/test/fixedbugs/bug461.go new file mode 100644 index 000000000..f0f7b0e69 --- /dev/null +++ b/test/fixedbugs/bug461.go @@ -0,0 +1,23 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// part two of issue 4124. Make sure reflect doesn't mark the field as exported. + +package main + +import "reflect" + +var T struct { + int +} + +func main() { + v := reflect.ValueOf(&T) + v = v.Elem().Field(0) + if v.CanSet() { + panic("int should be unexported") + } +} diff --git a/test/fixedbugs/bug462.go b/test/fixedbugs/bug462.go new file mode 100644 index 000000000..6434255c8 --- /dev/null +++ b/test/fixedbugs/bug462.go @@ -0,0 +1,19 @@ +// errorcheck + +// 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. + +package main + +import "os" + +type T struct { + File int +} + +func main() { + _ = T { + os.File: 1, // ERROR "unknown T field" + } +} diff --git a/test/fixedbugs/bug463.go b/test/fixedbugs/bug463.go new file mode 100644 index 000000000..3e7a18482 --- /dev/null +++ b/test/fixedbugs/bug463.go @@ -0,0 +1,22 @@ +// errorcheck + +// 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 3757: unhelpful typechecking loop message +// for constants that refer to themselves. + +package main + +const a = a // ERROR "refers to itself|definition loop" + +const ( + X = A + A = B // ERROR "refers to itself|definition loop" + B = D + C, D = 1, A +) + +func main() { +} diff --git a/test/fixedbugs/bug464.go b/test/fixedbugs/bug464.go new file mode 100644 index 000000000..582193997 --- /dev/null +++ b/test/fixedbugs/bug464.go @@ -0,0 +1,12 @@ +// errorcheck + +// 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 3937: unhelpful typechecking loop message +// for identifiers wrongly used as types. + +package main + +func foo(x foo) {} // ERROR "expected type|not a type" diff --git a/test/fixedbugs/bug465.dir/a.go b/test/fixedbugs/bug465.dir/a.go new file mode 100644 index 000000000..c5d410de4 --- /dev/null +++ b/test/fixedbugs/bug465.dir/a.go @@ -0,0 +1,61 @@ +// 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. + +package a + +type T struct{ A, B int } + +type A []int + +type M map[int]int + +func F1() int { + if (T{1, 2}) == (T{3, 4}) { + return 1 + } + return 0 +} + +func F2() int { + if (M{1: 2}) == nil { + return 1 + } + return 0 +} + +func F3() int { + if nil == (A{}) { + return 1 + } + return 0 +} + +func F4() int { + if a := (A{}); a == nil { + return 1 + } + return 0 +} + +func F5() int { + for k, v := range (M{1: 2}) { + return v - k + } + return 0 +} + +func F6() int { + switch a := (T{1, 1}); a == (T{1, 2}) { + default: + return 1 + } + return 0 +} + +func F7() int { + for m := (M{}); len(m) < (T{1, 2}).A; m[1] = (A{1})[0] { + return 1 + } + return 0 +} diff --git a/test/fixedbugs/bug465.dir/b.go b/test/fixedbugs/bug465.dir/b.go new file mode 100644 index 000000000..0f4909f4d --- /dev/null +++ b/test/fixedbugs/bug465.dir/b.go @@ -0,0 +1,17 @@ +// 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. + +package main + +import "./a" + +func main() { + for _, f := range []func() int{ + a.F1, a.F2, a.F3, a.F4, + a.F5, a.F6, a.F7} { + if f() > 1 { + panic("f() > 1") + } + } +} diff --git a/test/fixedbugs/bug465.go b/test/fixedbugs/bug465.go new file mode 100644 index 000000000..a6ef5876a --- /dev/null +++ b/test/fixedbugs/bug465.go @@ -0,0 +1,10 @@ +// rundir + +// 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 4230: inlining bug for composite literal in +// if, for, switch statements. + +package ignored diff --git a/test/fixedbugs/bug466.dir/a.go b/test/fixedbugs/bug466.dir/a.go new file mode 100644 index 000000000..b9de63eda --- /dev/null +++ b/test/fixedbugs/bug466.dir/a.go @@ -0,0 +1,15 @@ +// 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. + +package a + +const N = 2+3i + +func Func() []complex128 { + return []complex128{1, complex(2, 3), complex(4, 5)} +} + +func Mul(z complex128) complex128 { + return z * (3 + 4i) +} diff --git a/test/fixedbugs/bug466.dir/b.go b/test/fixedbugs/bug466.dir/b.go new file mode 100644 index 000000000..82d66eace --- /dev/null +++ b/test/fixedbugs/bug466.dir/b.go @@ -0,0 +1,30 @@ +// 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. + +package main + +import "./a" + +func main() { + s := a.Func() + if s[0] != 1 { + println(s[0]) + panic("s[0] != 1") + } + if s[1] != 2+3i { + println(s[1]) + panic("s[1] != 2+3i") + } + if s[2] != 4+5i { + println(s[2]) + panic("s[2] != 4+5i") + } + + x := 1 + 2i + y := a.Mul(x) + if y != (1+2i)*(3+4i) { + println(y) + panic("y != (1+2i)*(3+4i)") + } +} diff --git a/test/fixedbugs/bug466.go b/test/fixedbugs/bug466.go new file mode 100644 index 000000000..6b65b33b0 --- /dev/null +++ b/test/fixedbugs/bug466.go @@ -0,0 +1,11 @@ +// rundir + +// 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 4159: exported inlinable functions squash +// complex literals "a+bi" to "a+b". + +package ignored + diff --git a/test/fixedbugs/bug467.dir/p1.go b/test/fixedbugs/bug467.dir/p1.go new file mode 100644 index 000000000..538b554f8 --- /dev/null +++ b/test/fixedbugs/bug467.dir/p1.go @@ -0,0 +1,5 @@ +package p1 + +type SockaddrUnix int + +func (s SockaddrUnix) Error() string { return "blah" } diff --git a/test/fixedbugs/bug467.dir/p2.go b/test/fixedbugs/bug467.dir/p2.go new file mode 100644 index 000000000..d80d3a30b --- /dev/null +++ b/test/fixedbugs/bug467.dir/p2.go @@ -0,0 +1,5 @@ +package p2 + +import "./p1" + +func SockUnix() error { var s *p1.SockaddrUnix; return s } diff --git a/test/fixedbugs/bug467.dir/p3.go b/test/fixedbugs/bug467.dir/p3.go new file mode 100644 index 000000000..c79564647 --- /dev/null +++ b/test/fixedbugs/bug467.dir/p3.go @@ -0,0 +1,7 @@ +package main + +import "./p2" + +func main() { + _ = p2.SockUnix() +} diff --git a/test/fixedbugs/bug467.go b/test/fixedbugs/bug467.go new file mode 100644 index 000000000..d73adbadf --- /dev/null +++ b/test/fixedbugs/bug467.go @@ -0,0 +1,10 @@ +// compiledir + +// 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. + +// Exported data for inlining could forget types of +// local variables declared in inlinable bodies. + +package ignored diff --git a/test/fixedbugs/bug468.dir/p1.go b/test/fixedbugs/bug468.dir/p1.go new file mode 100644 index 000000000..ca175770f --- /dev/null +++ b/test/fixedbugs/bug468.dir/p1.go @@ -0,0 +1,7 @@ +// 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. + +package p1 + +type S struct { X, Y int } diff --git a/test/fixedbugs/bug468.dir/p2.go b/test/fixedbugs/bug468.dir/p2.go new file mode 100644 index 000000000..1793c0e53 --- /dev/null +++ b/test/fixedbugs/bug468.dir/p2.go @@ -0,0 +1,25 @@ +// 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. + +package main + +import ( + "reflect" + + "./p1" +) + +func main() { + var v1 = p1.S{1, 2} + var v2 = struct { X, Y int }{1, 2} + v1 = v2 + t1 := reflect.TypeOf(v1) + t2 := reflect.TypeOf(v2) + if !t1.AssignableTo(t2) { + panic(0) + } + if !t2.AssignableTo(t1) { + panic(1) + } +} diff --git a/test/fixedbugs/bug468.go b/test/fixedbugs/bug468.go new file mode 100644 index 000000000..12e4997d3 --- /dev/null +++ b/test/fixedbugs/bug468.go @@ -0,0 +1,10 @@ +// rundir + +// 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 reflect package was not correctly checking field names +// when checking for struct assignability. + +package ignored diff --git a/test/fixedbugs/bug469.go b/test/fixedbugs/bug469.go new file mode 100644 index 000000000..71157a4c4 --- /dev/null +++ b/test/fixedbugs/bug469.go @@ -0,0 +1,13 @@ +// 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/bug470.go b/test/fixedbugs/bug470.go new file mode 100644 index 000000000..0a359184c --- /dev/null +++ b/test/fixedbugs/bug470.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Converting constants between types must introduce rounding. + +package main + +import "fmt" + +const ( + F32 = 0.00999999977648258209228515625 + F64 = 0.01000000000000000020816681711721685132943093776702880859375 +) + +var F = float64(float32(0.01)) + +func main() { + // 0.01 rounded to float32 then to float64 is F32. + // 0.01 represented directly in float64 is F64. + if F != F32 { + panic(fmt.Sprintf("F=%.1000g, want %.1000g", F, F32)) + } +} diff --git a/test/fixedbugs/bug471.go b/test/fixedbugs/bug471.go new file mode 100644 index 000000000..e4542596e --- /dev/null +++ b/test/fixedbugs/bug471.go @@ -0,0 +1,18 @@ +// 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. + +// Caused an internal compiler error in gccgo. + +package p + +type C chan struct{} + +func (c C) F() { + select { + case c <- struct{}{}: + default: + } +} diff --git a/test/fixedbugs/bug472.dir/p1.go b/test/fixedbugs/bug472.dir/p1.go new file mode 100644 index 000000000..9d47fd84a --- /dev/null +++ b/test/fixedbugs/bug472.dir/p1.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 p1 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.Gosched } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.GC } + +func I() func() string { return runtime.Version } diff --git a/test/fixedbugs/bug472.dir/p2.go b/test/fixedbugs/bug472.dir/p2.go new file mode 100644 index 000000000..34a3f0487 --- /dev/null +++ b/test/fixedbugs/bug472.dir/p2.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 p2 + +import "runtime" + +func E() func() int { return runtime.NumCPU } + +func F() func() { return runtime.GC } + +func G() func() string { return runtime.GOROOT } + +func H() func() { return runtime.Gosched } + +func I() func() string { return runtime.Version } diff --git a/test/fixedbugs/bug472.dir/z.go b/test/fixedbugs/bug472.dir/z.go new file mode 100644 index 000000000..6c29dd08c --- /dev/null +++ b/test/fixedbugs/bug472.dir/z.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 main + +import ( + _ "./p1" + _ "./p2" +) + +func main() { +} diff --git a/test/fixedbugs/bug472.go b/test/fixedbugs/bug472.go new file mode 100644 index 000000000..c79c64ca1 --- /dev/null +++ b/test/fixedbugs/bug472.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. + +// Linker would incorrectly parse export data and think +// definitions are inconsistent. + +package ignored diff --git a/test/fixedbugs/bug473.go b/test/fixedbugs/bug473.go new file mode 100644 index 000000000..49ce7d737 --- /dev/null +++ b/test/fixedbugs/bug473.go @@ -0,0 +1,69 @@ +// 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. + +// Used to be miscompiled by gccgo, due to a bug in handling +// initialization ordering. + +package main + +func F(a ...interface{}) interface{} { + s := 0 + for _, v := range a { + s += v.(int) + } + return s +} + +var V1 = F(V10, V4, V3, V11) + +var V2 = F(V1) + +var V3 = F(1) + +var V4 = F(2) + +var V5 = F(3) + +var V6 = F(4) + +var V7 = F(5) + +var V8 = F(V14, V7, V3, V6, V5) + +var V9 = F(V4, F(V12)) + +var V10 = F(V4, V9) + +var V11 = F(6) + +var V12 = F(V5, V3, V8) + +var V13 = F(7) + +var V14 = F(8) + +func expect(name string, a interface{}, b int) { + if a.(int) != b { + panic(name) + } +} + +func main() { + expect("V1", V1, 38) + expect("V2", V2, 38) + expect("V3", V3, 1) + expect("V4", V4, 2) + expect("V5", V5, 3) + expect("V6", V6, 4) + expect("V7", V7, 5) + expect("V8", V8, 21) + expect("V9", V9, 27) + expect("V10", V10, 29) + expect("V11", V11, 6) + expect("V12", V12, 25) + expect("V13", V13, 7) + expect("V14", V14, 8) +} diff --git a/test/fixedbugs/issue2615.go b/test/fixedbugs/issue2615.go new file mode 100644 index 000000000..686e1e1ad --- /dev/null +++ b/test/fixedbugs/issue2615.go @@ -0,0 +1,547 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 2615: a long chain of else if's causes an overflow +// in the parser stack. + +package main + +// test returns the index of the lowest set bit in a 256-bit vector. +func test(x [4]uint64) int { + if x[0]&(1<<0) != 0 { + return 0 + } else if x[0]&(1<<1) != 0 { + return 1 + } else if x[0]&(1<<2) != 0 { + return 2 + } else if x[0]&(1<<3) != 0 { + return 3 + } else if x[0]&(1<<4) != 0 { + return 4 + } else if x[0]&(1<<5) != 0 { + return 5 + } else if x[0]&(1<<6) != 0 { + return 6 + } else if x[0]&(1<<7) != 0 { + return 7 + } else if x[0]&(1<<8) != 0 { + return 8 + } else if x[0]&(1<<9) != 0 { + return 9 + } else if x[0]&(1<<10) != 0 { + return 10 + } else if x[0]&(1<<11) != 0 { + return 11 + } else if x[0]&(1<<12) != 0 { + return 12 + } else if x[0]&(1<<13) != 0 { + return 13 + } else if x[0]&(1<<14) != 0 { + return 14 + } else if x[0]&(1<<15) != 0 { + return 15 + } else if x[0]&(1<<16) != 0 { + return 16 + } else if x[0]&(1<<17) != 0 { + return 17 + } else if x[0]&(1<<18) != 0 { + return 18 + } else if x[0]&(1<<19) != 0 { + return 19 + } else if x[0]&(1<<20) != 0 { + return 20 + } else if x[0]&(1<<21) != 0 { + return 21 + } else if x[0]&(1<<22) != 0 { + return 22 + } else if x[0]&(1<<23) != 0 { + return 23 + } else if x[0]&(1<<24) != 0 { + return 24 + } else if x[0]&(1<<25) != 0 { + return 25 + } else if x[0]&(1<<26) != 0 { + return 26 + } else if x[0]&(1<<27) != 0 { + return 27 + } else if x[0]&(1<<28) != 0 { + return 28 + } else if x[0]&(1<<29) != 0 { + return 29 + } else if x[0]&(1<<30) != 0 { + return 30 + } else if x[0]&(1<<31) != 0 { + return 31 + } else if x[0]&(1<<32) != 0 { + return 32 + } else if x[0]&(1<<33) != 0 { + return 33 + } else if x[0]&(1<<34) != 0 { + return 34 + } else if x[0]&(1<<35) != 0 { + return 35 + } else if x[0]&(1<<36) != 0 { + return 36 + } else if x[0]&(1<<37) != 0 { + return 37 + } else if x[0]&(1<<38) != 0 { + return 38 + } else if x[0]&(1<<39) != 0 { + return 39 + } else if x[0]&(1<<40) != 0 { + return 40 + } else if x[0]&(1<<41) != 0 { + return 41 + } else if x[0]&(1<<42) != 0 { + return 42 + } else if x[0]&(1<<43) != 0 { + return 43 + } else if x[0]&(1<<44) != 0 { + return 44 + } else if x[0]&(1<<45) != 0 { + return 45 + } else if x[0]&(1<<46) != 0 { + return 46 + } else if x[0]&(1<<47) != 0 { + return 47 + } else if x[0]&(1<<48) != 0 { + return 48 + } else if x[0]&(1<<49) != 0 { + return 49 + } else if x[0]&(1<<50) != 0 { + return 50 + } else if x[0]&(1<<51) != 0 { + return 51 + } else if x[0]&(1<<52) != 0 { + return 52 + } else if x[0]&(1<<53) != 0 { + return 53 + } else if x[0]&(1<<54) != 0 { + return 54 + } else if x[0]&(1<<55) != 0 { + return 55 + } else if x[0]&(1<<56) != 0 { + return 56 + } else if x[0]&(1<<57) != 0 { + return 57 + } else if x[0]&(1<<58) != 0 { + return 58 + } else if x[0]&(1<<59) != 0 { + return 59 + } else if x[0]&(1<<60) != 0 { + return 60 + } else if x[0]&(1<<61) != 0 { + return 61 + } else if x[0]&(1<<62) != 0 { + return 62 + } else if x[0]&(1<<63) != 0 { + return 63 + } else if x[1]&(1<<0) != 0 { + return 64 + } else if x[1]&(1<<1) != 0 { + return 65 + } else if x[1]&(1<<2) != 0 { + return 66 + } else if x[1]&(1<<3) != 0 { + return 67 + } else if x[1]&(1<<4) != 0 { + return 68 + } else if x[1]&(1<<5) != 0 { + return 69 + } else if x[1]&(1<<6) != 0 { + return 70 + } else if x[1]&(1<<7) != 0 { + return 71 + } else if x[1]&(1<<8) != 0 { + return 72 + } else if x[1]&(1<<9) != 0 { + return 73 + } else if x[1]&(1<<10) != 0 { + return 74 + } else if x[1]&(1<<11) != 0 { + return 75 + } else if x[1]&(1<<12) != 0 { + return 76 + } else if x[1]&(1<<13) != 0 { + return 77 + } else if x[1]&(1<<14) != 0 { + return 78 + } else if x[1]&(1<<15) != 0 { + return 79 + } else if x[1]&(1<<16) != 0 { + return 80 + } else if x[1]&(1<<17) != 0 { + return 81 + } else if x[1]&(1<<18) != 0 { + return 82 + } else if x[1]&(1<<19) != 0 { + return 83 + } else if x[1]&(1<<20) != 0 { + return 84 + } else if x[1]&(1<<21) != 0 { + return 85 + } else if x[1]&(1<<22) != 0 { + return 86 + } else if x[1]&(1<<23) != 0 { + return 87 + } else if x[1]&(1<<24) != 0 { + return 88 + } else if x[1]&(1<<25) != 0 { + return 89 + } else if x[1]&(1<<26) != 0 { + return 90 + } else if x[1]&(1<<27) != 0 { + return 91 + } else if x[1]&(1<<28) != 0 { + return 92 + } else if x[1]&(1<<29) != 0 { + return 93 + } else if x[1]&(1<<30) != 0 { + return 94 + } else if x[1]&(1<<31) != 0 { + return 95 + } else if x[1]&(1<<32) != 0 { + return 96 + } else if x[1]&(1<<33) != 0 { + return 97 + } else if x[1]&(1<<34) != 0 { + return 98 + } else if x[1]&(1<<35) != 0 { + return 99 + } else if x[1]&(1<<36) != 0 { + return 100 + } else if x[1]&(1<<37) != 0 { + return 101 + } else if x[1]&(1<<38) != 0 { + return 102 + } else if x[1]&(1<<39) != 0 { + return 103 + } else if x[1]&(1<<40) != 0 { + return 104 + } else if x[1]&(1<<41) != 0 { + return 105 + } else if x[1]&(1<<42) != 0 { + return 106 + } else if x[1]&(1<<43) != 0 { + return 107 + } else if x[1]&(1<<44) != 0 { + return 108 + } else if x[1]&(1<<45) != 0 { + return 109 + } else if x[1]&(1<<46) != 0 { + return 110 + } else if x[1]&(1<<47) != 0 { + return 111 + } else if x[1]&(1<<48) != 0 { + return 112 + } else if x[1]&(1<<49) != 0 { + return 113 + } else if x[1]&(1<<50) != 0 { + return 114 + } else if x[1]&(1<<51) != 0 { + return 115 + } else if x[1]&(1<<52) != 0 { + return 116 + } else if x[1]&(1<<53) != 0 { + return 117 + } else if x[1]&(1<<54) != 0 { + return 118 + } else if x[1]&(1<<55) != 0 { + return 119 + } else if x[1]&(1<<56) != 0 { + return 120 + } else if x[1]&(1<<57) != 0 { + return 121 + } else if x[1]&(1<<58) != 0 { + return 122 + } else if x[1]&(1<<59) != 0 { + return 123 + } else if x[1]&(1<<60) != 0 { + return 124 + } else if x[1]&(1<<61) != 0 { + return 125 + } else if x[1]&(1<<62) != 0 { + return 126 + } else if x[1]&(1<<63) != 0 { + return 127 + } else if x[2]&(1<<0) != 0 { + return 128 + } else if x[2]&(1<<1) != 0 { + return 129 + } else if x[2]&(1<<2) != 0 { + return 130 + } else if x[2]&(1<<3) != 0 { + return 131 + } else if x[2]&(1<<4) != 0 { + return 132 + } else if x[2]&(1<<5) != 0 { + return 133 + } else if x[2]&(1<<6) != 0 { + return 134 + } else if x[2]&(1<<7) != 0 { + return 135 + } else if x[2]&(1<<8) != 0 { + return 136 + } else if x[2]&(1<<9) != 0 { + return 137 + } else if x[2]&(1<<10) != 0 { + return 138 + } else if x[2]&(1<<11) != 0 { + return 139 + } else if x[2]&(1<<12) != 0 { + return 140 + } else if x[2]&(1<<13) != 0 { + return 141 + } else if x[2]&(1<<14) != 0 { + return 142 + } else if x[2]&(1<<15) != 0 { + return 143 + } else if x[2]&(1<<16) != 0 { + return 144 + } else if x[2]&(1<<17) != 0 { + return 145 + } else if x[2]&(1<<18) != 0 { + return 146 + } else if x[2]&(1<<19) != 0 { + return 147 + } else if x[2]&(1<<20) != 0 { + return 148 + } else if x[2]&(1<<21) != 0 { + return 149 + } else if x[2]&(1<<22) != 0 { + return 150 + } else if x[2]&(1<<23) != 0 { + return 151 + } else if x[2]&(1<<24) != 0 { + return 152 + } else if x[2]&(1<<25) != 0 { + return 153 + } else if x[2]&(1<<26) != 0 { + return 154 + } else if x[2]&(1<<27) != 0 { + return 155 + } else if x[2]&(1<<28) != 0 { + return 156 + } else if x[2]&(1<<29) != 0 { + return 157 + } else if x[2]&(1<<30) != 0 { + return 158 + } else if x[2]&(1<<31) != 0 { + return 159 + } else if x[2]&(1<<32) != 0 { + return 160 + } else if x[2]&(1<<33) != 0 { + return 161 + } else if x[2]&(1<<34) != 0 { + return 162 + } else if x[2]&(1<<35) != 0 { + return 163 + } else if x[2]&(1<<36) != 0 { + return 164 + } else if x[2]&(1<<37) != 0 { + return 165 + } else if x[2]&(1<<38) != 0 { + return 166 + } else if x[2]&(1<<39) != 0 { + return 167 + } else if x[2]&(1<<40) != 0 { + return 168 + } else if x[2]&(1<<41) != 0 { + return 169 + } else if x[2]&(1<<42) != 0 { + return 170 + } else if x[2]&(1<<43) != 0 { + return 171 + } else if x[2]&(1<<44) != 0 { + return 172 + } else if x[2]&(1<<45) != 0 { + return 173 + } else if x[2]&(1<<46) != 0 { + return 174 + } else if x[2]&(1<<47) != 0 { + return 175 + } else if x[2]&(1<<48) != 0 { + return 176 + } else if x[2]&(1<<49) != 0 { + return 177 + } else if x[2]&(1<<50) != 0 { + return 178 + } else if x[2]&(1<<51) != 0 { + return 179 + } else if x[2]&(1<<52) != 0 { + return 180 + } else if x[2]&(1<<53) != 0 { + return 181 + } else if x[2]&(1<<54) != 0 { + return 182 + } else if x[2]&(1<<55) != 0 { + return 183 + } else if x[2]&(1<<56) != 0 { + return 184 + } else if x[2]&(1<<57) != 0 { + return 185 + } else if x[2]&(1<<58) != 0 { + return 186 + } else if x[2]&(1<<59) != 0 { + return 187 + } else if x[2]&(1<<60) != 0 { + return 188 + } else if x[2]&(1<<61) != 0 { + return 189 + } else if x[2]&(1<<62) != 0 { + return 190 + } else if x[2]&(1<<63) != 0 { + return 191 + } else if x[3]&(1<<0) != 0 { + return 192 + } else if x[3]&(1<<1) != 0 { + return 193 + } else if x[3]&(1<<2) != 0 { + return 194 + } else if x[3]&(1<<3) != 0 { + return 195 + } else if x[3]&(1<<4) != 0 { + return 196 + } else if x[3]&(1<<5) != 0 { + return 197 + } else if x[3]&(1<<6) != 0 { + return 198 + } else if x[3]&(1<<7) != 0 { + return 199 + } else if x[3]&(1<<8) != 0 { + return 200 + } else if x[3]&(1<<9) != 0 { + return 201 + } else if x[3]&(1<<10) != 0 { + return 202 + } else if x[3]&(1<<11) != 0 { + return 203 + } else if x[3]&(1<<12) != 0 { + return 204 + } else if x[3]&(1<<13) != 0 { + return 205 + } else if x[3]&(1<<14) != 0 { + return 206 + } else if x[3]&(1<<15) != 0 { + return 207 + } else if x[3]&(1<<16) != 0 { + return 208 + } else if x[3]&(1<<17) != 0 { + return 209 + } else if x[3]&(1<<18) != 0 { + return 210 + } else if x[3]&(1<<19) != 0 { + return 211 + } else if x[3]&(1<<20) != 0 { + return 212 + } else if x[3]&(1<<21) != 0 { + return 213 + } else if x[3]&(1<<22) != 0 { + return 214 + } else if x[3]&(1<<23) != 0 { + return 215 + } else if x[3]&(1<<24) != 0 { + return 216 + } else if x[3]&(1<<25) != 0 { + return 217 + } else if x[3]&(1<<26) != 0 { + return 218 + } else if x[3]&(1<<27) != 0 { + return 219 + } else if x[3]&(1<<28) != 0 { + return 220 + } else if x[3]&(1<<29) != 0 { + return 221 + } else if x[3]&(1<<30) != 0 { + return 222 + } else if x[3]&(1<<31) != 0 { + return 223 + } else if x[3]&(1<<32) != 0 { + return 224 + } else if x[3]&(1<<33) != 0 { + return 225 + } else if x[3]&(1<<34) != 0 { + return 226 + } else if x[3]&(1<<35) != 0 { + return 227 + } else if x[3]&(1<<36) != 0 { + return 228 + } else if x[3]&(1<<37) != 0 { + return 229 + } else if x[3]&(1<<38) != 0 { + return 230 + } else if x[3]&(1<<39) != 0 { + return 231 + } else if x[3]&(1<<40) != 0 { + return 232 + } else if x[3]&(1<<41) != 0 { + return 233 + } else if x[3]&(1<<42) != 0 { + return 234 + } else if x[3]&(1<<43) != 0 { + return 235 + } else if x[3]&(1<<44) != 0 { + return 236 + } else if x[3]&(1<<45) != 0 { + return 237 + } else if x[3]&(1<<46) != 0 { + return 238 + } else if x[3]&(1<<47) != 0 { + return 239 + } else if x[3]&(1<<48) != 0 { + return 240 + } else if x[3]&(1<<49) != 0 { + return 241 + } else if x[3]&(1<<50) != 0 { + return 242 + } else if x[3]&(1<<51) != 0 { + return 243 + } else if x[3]&(1<<52) != 0 { + return 244 + } else if x[3]&(1<<53) != 0 { + return 245 + } else if x[3]&(1<<54) != 0 { + return 246 + } else if x[3]&(1<<55) != 0 { + return 247 + } else if x[3]&(1<<56) != 0 { + return 248 + } else if x[3]&(1<<57) != 0 { + return 249 + } else if x[3]&(1<<58) != 0 { + return 250 + } else if x[3]&(1<<59) != 0 { + return 251 + } else if x[3]&(1<<60) != 0 { + return 252 + } else if x[3]&(1<<61) != 0 { + return 253 + } else if x[3]&(1<<62) != 0 { + return 254 + } else if x[3]&(1<<63) != 0 { + return 255 + } + return -1 +} + +func main() { + const ones = ^uint64(0) + for i := 0; i < 256; i++ { + bits := [4]uint64{ones, ones, ones, ones} + + // clear bottom i bits + bits[i/64] ^= 1<<(uint(i)&63) - 1 + for j := i/64 - 1; j >= 0; j-- { + bits[j] = 0 + } + + k := test(bits) + if k != i { + print("test(bits)=", k, " want ", i, "\n") + panic("failed") + } + } +} diff --git a/test/fixedbugs/issue3552.dir/one.go b/test/fixedbugs/issue3552.dir/one.go new file mode 100644 index 000000000..491ada1d9 --- /dev/null +++ b/test/fixedbugs/issue3552.dir/one.go @@ -0,0 +1,28 @@ +// 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. + +package one + +// Issue 3552 + +type T struct { int } + +func (t T) F() int { return t.int } + +type U struct { int int } + +func (u U) F() int { return u.int } + +type lint int + +type V struct { lint } + +func (v V) F() int { return int(v.lint) } + +type W struct { lint lint } + +func (w W) F() int { return int(w.lint) } + + + diff --git a/test/fixedbugs/bug392.dir/three.go b/test/fixedbugs/issue3552.dir/two.go index a6193bf91..1366d244d 100644 --- a/test/fixedbugs/bug392.dir/three.go +++ b/test/fixedbugs/issue3552.dir/two.go @@ -5,9 +5,18 @@ // Use the functions in one.go so that the inlined // forms get type-checked. -package three +package two -import "./two" +import "./one" -var x = two.F() -var v = two.V +func use() { + var t one.T + var u one.U + var v one.V + var w one.W + + _ = t.F() + _ = u.F() + _ = v.F() + _ = w.F() +} diff --git a/test/fixedbugs/issue3552.go b/test/fixedbugs/issue3552.go new file mode 100644 index 000000000..a198dbe97 --- /dev/null +++ b/test/fixedbugs/issue3552.go @@ -0,0 +1,10 @@ +// compiledir + +// Copyright 2011 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 3552: cross-package inlining misbehaves when +// referencing embedded builtins. + +package ignored diff --git a/test/fixedbugs/issue3705.go b/test/fixedbugs/issue3705.go new file mode 100644 index 000000000..c19bcea1c --- /dev/null +++ b/test/fixedbugs/issue3705.go @@ -0,0 +1,9 @@ +// errorcheck + +// 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. + +package p + +func init() // ERROR "missing function body" diff --git a/test/fixedbugs/issue3783.go b/test/fixedbugs/issue3783.go new file mode 100644 index 000000000..35df5d8f6 --- /dev/null +++ b/test/fixedbugs/issue3783.go @@ -0,0 +1,12 @@ +// errorcheck + +// 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. + +package foo + +var i int + +func (*i) bar() // ERROR "not a type" + diff --git a/test/fixedbugs/issue3924.go b/test/fixedbugs/issue3924.go new file mode 100644 index 000000000..d4739b21c --- /dev/null +++ b/test/fixedbugs/issue3924.go @@ -0,0 +1,13 @@ +// errorcheck + +// 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. + +package foo + +type mybool bool + +var x, y = 1, 2 +var _ mybool = x < y && x < y // ERROR "cannot use" +var _ mybool = x < y || x < y // ERROR "cannot use" diff --git a/test/fixedbugs/issue3925.go b/test/fixedbugs/issue3925.go new file mode 100644 index 000000000..2f8786fc7 --- /dev/null +++ b/test/fixedbugs/issue3925.go @@ -0,0 +1,23 @@ +// errorcheck + +// 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 3925: wrong line number for error message "missing key in map literal" + +// also a test for correct line number in other malformed composite literals. + +package foo + +var _ = map[string]string{ + "1": "2", + "3", "4", // ERROR "missing key" +} + +var _ = []string{ + "foo", + "bar", + 20, // ERROR "cannot use" +} + diff --git a/test/fixedbugs/issue4066.go b/test/fixedbugs/issue4066.go new file mode 100644 index 000000000..19cfe6651 --- /dev/null +++ b/test/fixedbugs/issue4066.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// issue 4066: return values not being spilled eagerly enough + +package main + +func main() { + n := foo() + if n != 2 { + println(n) + panic("wrong return value") + } +} + +type terr struct{} + +func foo() (val int) { + val = 0 + defer func() { + if x := recover(); x != nil { + _ = x.(terr) + } + }() + for { + val = 2 + foo1() + } + panic("unreachable") +} + +func foo1() { + panic(terr{}) +} diff --git a/test/fixedbugs/issue4085a.go b/test/fixedbugs/issue4085a.go new file mode 100644 index 000000000..8a52b268f --- /dev/null +++ b/test/fixedbugs/issue4085a.go @@ -0,0 +1,18 @@ +// 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 + +type T []int + +func main() { + _ = make(T, -1) // ERROR "negative" + _ = make(T, 0.5) // ERROR "constant 0.5 truncated to integer" + _ = make(T, 1.0) // ok + _ = make(T, 1<<63) // ERROR "len argument too large" + _ = make(T, 0, -1) // ERROR "negative cap" + _ = make(T, 10, 0) // ERROR "len larger than cap" +} diff --git a/test/fixedbugs/issue4085b.go b/test/fixedbugs/issue4085b.go new file mode 100644 index 000000000..63aca2378 --- /dev/null +++ b/test/fixedbugs/issue4085b.go @@ -0,0 +1,49 @@ +// 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. + +package main + +import ( + "strings" + "unsafe" +) + +type T []int + +func main() { + n := -1 + shouldPanic("len out of range", func() {_ = make(T, n)}) + shouldPanic("cap out of range", func() {_ = make(T, 0, n)}) + var t *byte + if unsafe.Sizeof(t) == 8 { + n = 1<<20 + n <<= 20 + shouldPanic("len out of range", func() {_ = make(T, n)}) + shouldPanic("cap out of range", func() {_ = make(T, 0, n)}) + n <<= 20 + shouldPanic("len out of range", func() {_ = make(T, n)}) + shouldPanic("cap out of range", func() {_ = make(T, 0, n)}) + } else { + n = 1<<31 - 1 + shouldPanic("len out of range", func() {_ = make(T, n)}) + shouldPanic("cap out of range", func() {_ = make(T, 0, n)}) + } +} + +func shouldPanic(str string, f func()) { + defer func() { + err := recover() + if err == nil { + panic("did not panic") + } + s := err.(error).Error() + if !strings.Contains(s, str) { + panic("got panic " + s + ", want " + str) + } + }() + + f() +} diff --git a/test/fixedbugs/issue4097.go b/test/fixedbugs/issue4097.go new file mode 100644 index 000000000..fa942c9db --- /dev/null +++ b/test/fixedbugs/issue4097.go @@ -0,0 +1,11 @@ +// errorcheck + +// 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. + +package foo + +var s [][10]int +const m = len(s[len(s)-1]) // ERROR "is not a constant" + diff --git a/test/fixedbugs/issue4099.go b/test/fixedbugs/issue4099.go new file mode 100644 index 000000000..89392bfff --- /dev/null +++ b/test/fixedbugs/issue4099.go @@ -0,0 +1,26 @@ +// errorcheck -0 -m + +// 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. + +// Check go:noescape annotations. + +package p + +// The noescape comment only applies to the next func, +// which must not have a body. + +//go:noescape + +func F1([]byte) + +func F2([]byte) + +func G() { + var buf1 [10]byte + F1(buf1[:]) // ERROR "buf1 does not escape" + + var buf2 [10]byte // ERROR "moved to heap: buf2" + F2(buf2[:]) // ERROR "buf2 escapes to heap" +} diff --git a/test/fixedbugs/issue4162.go b/test/fixedbugs/issue4162.go new file mode 100644 index 000000000..c2a8338c7 --- /dev/null +++ b/test/fixedbugs/issue4162.go @@ -0,0 +1,17 @@ +// 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 4162. Trailing commas now allowed in conversions. + +package p + +// All these are valid now. +var ( + _ = int(1.0,) // comma was always permitted (like function call) + _ = []byte("foo",) // was syntax error: unexpected comma + _ = chan int(nil,) // was syntax error: unexpected comma + _ = (func())(nil,) // was syntax error: unexpected comma +) diff --git a/test/fixedbugs/issue4167.go b/test/fixedbugs/issue4167.go new file mode 100644 index 000000000..4e353312b --- /dev/null +++ b/test/fixedbugs/issue4167.go @@ -0,0 +1,50 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4167: inlining of a (*T).Method expression taking +// its arguments from a multiple return breaks the compiler. + +package main + +type pa []int + +type p int + +func (this *pa) func1() (v *p, c int) { + for _ = range *this { + c++ + } + v = (*p)(&c) + return +} + +func (this *pa) func2() p { + return (*p).func3(this.func1()) +} + +func (this *p) func3(f int) p { + return *this +} + +func (this *pa) func2dots() p { + return (*p).func3(this.func1()) +} + +func (this *p) func3dots(f ...int) p { + return *this +} + +func main() { + arr := make(pa, 13) + length := arr.func2() + if int(length) != len(arr) { + panic("length != len(arr)") + } + length = arr.func2dots() + if int(length) != len(arr) { + panic("length != len(arr)") + } +} diff --git a/test/fixedbugs/issue4232.go b/test/fixedbugs/issue4232.go new file mode 100644 index 000000000..29ddfa8a9 --- /dev/null +++ b/test/fixedbugs/issue4232.go @@ -0,0 +1,33 @@ +// 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 p + +func f() { + var a [10]int + _ = a[-1] // ERROR "invalid array index -1" + _ = a[-1:] // ERROR "invalid slice index -1" + _ = a[:-1] // ERROR "invalid slice index -1" + _ = a[10] // ERROR "invalid array index 10" + + var s []int + _ = s[-1] // ERROR "invalid slice index -1" + _ = s[-1:] // ERROR "invalid slice index -1" + _ = s[:-1] // ERROR "invalid slice index -1" + _ = s[10] + + const c = "foo" + _ = c[-1] // ERROR "invalid string index -1" + _ = c[-1:] // ERROR "invalid slice index -1" + _ = c[:-1] // ERROR "invalid slice index -1" + _ = c[3] // ERROR "invalid string index 3" + + var t string + _ = t[-1] // ERROR "invalid string index -1" + _ = t[-1:] // ERROR "invalid slice index -1" + _ = t[:-1] // ERROR "invalid slice index -1" + _ = t[3] +} diff --git a/test/fixedbugs/issue4251.go b/test/fixedbugs/issue4251.go new file mode 100644 index 000000000..a14e0896a --- /dev/null +++ b/test/fixedbugs/issue4251.go @@ -0,0 +1,21 @@ +// errorcheck + +// 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 4251: slice with inverted range is an error. + +package p + +func F1(s []byte) []byte { + return s[2:1] // ERROR "inverted" +} + +func F2(a [10]byte) []byte { + return a[2:1] // ERROR "inverted" +} + +func F3(s string) string { + return s[2:1] // ERROR "inverted" +} diff --git a/test/fixedbugs/issue4252.dir/a.go b/test/fixedbugs/issue4252.dir/a.go new file mode 100644 index 000000000..089b6f20f --- /dev/null +++ b/test/fixedbugs/issue4252.dir/a.go @@ -0,0 +1,35 @@ +// 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. + +// A package that redeclares common builtin names. +package a + +var true = 0 == 1 +var false = 0 == 0 +var nil = 1 + +const append = 42 + +type error bool +type int interface{} + +func len(interface{}) int32 { return 42 } + +func Test() { + var array [append]int + if true { + panic("unexpected builtin true instead of redeclared one") + } + if !false { + panic("unexpected builtin false instead of redeclared one") + } + if len(array) != 42 { + println(len(array)) + panic("unexpected call of builtin len") + } +} + +func InlinedFakeTrue() error { return error(true) } +func InlinedFakeFalse() error { return error(false) } +func InlinedFakeNil() int { return nil } diff --git a/test/fixedbugs/issue4252.dir/main.go b/test/fixedbugs/issue4252.dir/main.go new file mode 100644 index 000000000..28e434224 --- /dev/null +++ b/test/fixedbugs/issue4252.dir/main.go @@ -0,0 +1,20 @@ +// 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. + +package main + +import "./a" + +func main() { + if a.InlinedFakeTrue() { + panic("returned true was the real one") + } + if !a.InlinedFakeFalse() { + panic("returned false was the real one") + } + if a.InlinedFakeNil() == nil { + panic("returned nil was the real one") + } + a.Test() +} diff --git a/test/fixedbugs/issue4252.go b/test/fixedbugs/issue4252.go new file mode 100644 index 000000000..1b0e5b202 --- /dev/null +++ b/test/fixedbugs/issue4252.go @@ -0,0 +1,11 @@ +// rundir + +// 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 4252: tests that fixing the issue still allow +// builtins to be redeclared and are not corrupted +// in export data. + +package ignored diff --git a/test/fixedbugs/issue4264.go b/test/fixedbugs/issue4264.go new file mode 100644 index 000000000..627393211 --- /dev/null +++ b/test/fixedbugs/issue4264.go @@ -0,0 +1,19 @@ +// 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 4264: reject int division by const 0 + +package main + +func main() { + var x int + var y float64 + var z complex128 + + println(x/0) // ERROR "division by zero" + println(y/0) + println(z/0) +}
\ No newline at end of file diff --git a/test/fixedbugs/issue4283.go b/test/fixedbugs/issue4283.go new file mode 100644 index 000000000..128c87231 --- /dev/null +++ b/test/fixedbugs/issue4283.go @@ -0,0 +1,17 @@ +// errorcheck + +// 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 4283: nil == nil can't be done as the type is unknown. + +package p + +func F1() bool { + return nil == nil // ERROR "invalid" +} + +func F2() bool { + return nil != nil // ERROR "invalid" +} diff --git a/test/fixedbugs/issue4313.go b/test/fixedbugs/issue4313.go new file mode 100644 index 000000000..b2f69dbfa --- /dev/null +++ b/test/fixedbugs/issue4313.go @@ -0,0 +1,28 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Order of operations in select. + +package main + +func main() { + c := make(chan int, 1) + x := 0 + select { + case c <- x: // should see x = 0, not x = 42 (after makec) + case <-makec(&x): // should be evaluated only after c and x on previous line + } + y := <-c + if y != 0 { + panic(y) + } +} + +func makec(px *int) chan bool { + if false { for {} } + *px = 42 + return make(chan bool, 0) +} diff --git a/test/fixedbugs/issue4316.go b/test/fixedbugs/issue4316.go new file mode 100644 index 000000000..bb18a0896 --- /dev/null +++ b/test/fixedbugs/issue4316.go @@ -0,0 +1,64 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4316: the stack overflow check in the linker +// is confused when it encounters a split-stack function +// that needs 0 bytes of stack space. + +package main + +type Peano *Peano + +func makePeano(n int) *Peano { + if n == 0 { + return nil + } + p := Peano(makePeano(n - 1)) + return &p +} + +var countArg Peano +var countResult int + +func countPeano() { + if countArg == nil { + countResult = 0 + return + } + countArg = *countArg + countPeano() + countResult++ +} + +var s = "(())" +var pT = 0 + +func p() { + if pT >= len(s) { + return + } + if s[pT] == '(' { + pT += 1 + p() + if pT < len(s) && s[pT] == ')' { + pT += 1 + } else { + return + } + p() + } +} + +func main() { + countArg = makePeano(4096) + countPeano() + if countResult != 4096 { + println("countResult =", countResult) + panic("countResult != 4096") + } + + p() +} diff --git a/test/fixedbugs/issue4323.go b/test/fixedbugs/issue4323.go new file mode 100644 index 000000000..6bb78f43c --- /dev/null +++ b/test/fixedbugs/issue4323.go @@ -0,0 +1,31 @@ +// 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 4323: inlining of functions with local variables +// forgets to typecheck the declarations in the inlined copy. + +package main + +type reader struct { + C chan T +} + +type T struct{ C chan []byte } + +var r = newReader() + +func newReader() *reader { return new(reader) } + +func (r *reader) Read(n int) ([]byte, error) { + req := T{C: make(chan []byte)} + r.C <- req + return <-req.C, nil +} + +func main() { + s, err := r.Read(1) + _, _ = s, err +} diff --git a/test/fixedbugs/issue4326.dir/p1.go b/test/fixedbugs/issue4326.dir/p1.go new file mode 100644 index 000000000..ab214befb --- /dev/null +++ b/test/fixedbugs/issue4326.dir/p1.go @@ -0,0 +1,12 @@ +package p1 + +type O map[string]map[string]string + +func (opts O) RemoveOption(sect, opt string) bool { + if _, ok := opts[sect]; !ok { + return false + } + _, ok := opts[sect][opt] + delete(opts[sect], opt) + return ok +} diff --git a/test/fixedbugs/issue4326.dir/p2.go b/test/fixedbugs/issue4326.dir/p2.go new file mode 100644 index 000000000..8e86266dd --- /dev/null +++ b/test/fixedbugs/issue4326.dir/p2.go @@ -0,0 +1,5 @@ +package p2 + +import "./p1" + +func NewO() p1.O { return nil } diff --git a/test/fixedbugs/issue4326.dir/q1.go b/test/fixedbugs/issue4326.dir/q1.go new file mode 100644 index 000000000..f118eb092 --- /dev/null +++ b/test/fixedbugs/issue4326.dir/q1.go @@ -0,0 +1,8 @@ +package q1 + +func Deref(typ interface{}) interface{} { + if typ, ok := typ.(*int); ok { + return *typ + } + return typ +} diff --git a/test/fixedbugs/issue4326.dir/q2.go b/test/fixedbugs/issue4326.dir/q2.go new file mode 100644 index 000000000..075e2b21e --- /dev/null +++ b/test/fixedbugs/issue4326.dir/q2.go @@ -0,0 +1,11 @@ +package main + +import "./q1" + +func main() { + x := 1 + y := q1.Deref(&x) + if y != 1 { + panic("y != 1") + } +} diff --git a/test/fixedbugs/issue4326.dir/z.go b/test/fixedbugs/issue4326.dir/z.go new file mode 100644 index 000000000..9b222e8b4 --- /dev/null +++ b/test/fixedbugs/issue4326.dir/z.go @@ -0,0 +1,7 @@ +package z + +import "./p2" + +func main() { + p2.NewO().RemoveOption("hello", "world") +} diff --git a/test/fixedbugs/issue4326.go b/test/fixedbugs/issue4326.go new file mode 100644 index 000000000..5ce2eea26 --- /dev/null +++ b/test/fixedbugs/issue4326.go @@ -0,0 +1,9 @@ +// compiledir + +// 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. + +// Printing local variables in inliner shadows global names. + +package ignored diff --git a/test/fixedbugs/issue4348.go b/test/fixedbugs/issue4348.go new file mode 100644 index 000000000..3dac8f768 --- /dev/null +++ b/test/fixedbugs/issue4348.go @@ -0,0 +1,29 @@ +// 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 4348. After switch to 64-bit ints the compiler generates +// illegal instructions when using large array bounds or indexes. + +package main + +// 1<<32 on a 64-bit machine, 1 otherwise. +const LARGE = ^uint(0)>>32 + 1 + +func A() int { + var a []int + return a[LARGE] +} + +var b [LARGE]int + +func B(i int) int { + return b[i] +} + +func main() { + n := A() + B(n) +} diff --git a/test/fixedbugs/issue4353.go b/test/fixedbugs/issue4353.go new file mode 100644 index 000000000..defe7c324 --- /dev/null +++ b/test/fixedbugs/issue4353.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4353. An optimizer bug in 8g triggers a runtime fault +// instead of an out of bounds panic. + +package main + +var aib [100000]int +var paib *[100000]int = &aib +var i64 int64 = 100023 + +func main() { + defer func() { recover() }() + _ = paib[i64] +} diff --git a/test/fixedbugs/issue4359.go b/test/fixedbugs/issue4359.go new file mode 100644 index 000000000..b5adb4010 --- /dev/null +++ b/test/fixedbugs/issue4359.go @@ -0,0 +1,19 @@ +// errorcheck + +// 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 4359: wrong handling of broken struct fields +// causes "internal compiler error: lookdot badwidth". + +package main + +type T struct { + x T1 // ERROR "undefined" +} + +func f() { + var t *T + _ = t.x +} diff --git a/test/fixedbugs/issue4370.dir/p1.go b/test/fixedbugs/issue4370.dir/p1.go new file mode 100644 index 000000000..d732c8b36 --- /dev/null +++ b/test/fixedbugs/issue4370.dir/p1.go @@ -0,0 +1,20 @@ +// 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. + +package p1 + +type Magic int + +type T struct { + x interface{} +} + +func (t *T) M() bool { + _, ok := t.x.(Magic) + return ok +} + +func F(t *T) { + println(t) +} diff --git a/test/fixedbugs/issue4370.dir/p2.go b/test/fixedbugs/issue4370.dir/p2.go new file mode 100644 index 000000000..33370d07a --- /dev/null +++ b/test/fixedbugs/issue4370.dir/p2.go @@ -0,0 +1,16 @@ +// 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. + +package p2 + +import "./p1" + +type T struct { + p1.T +} + +func F() { + var t T + p1.F(&t.T) +} diff --git a/test/fixedbugs/issue4370.dir/p3.go b/test/fixedbugs/issue4370.dir/p3.go new file mode 100644 index 000000000..13c996bc2 --- /dev/null +++ b/test/fixedbugs/issue4370.dir/p3.go @@ -0,0 +1,13 @@ +// 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. + +package p3 + +import "./p2" + +func F() { + p2.F() + var t p2.T + println(t.T.M()) +} diff --git a/test/fixedbugs/issue4370.go b/test/fixedbugs/issue4370.go new file mode 100644 index 000000000..76b47e1a6 --- /dev/null +++ b/test/fixedbugs/issue4370.go @@ -0,0 +1,9 @@ +// compiledir + +// 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. + +// Re-exporting inlined function bodies missed types in x, ok := v.(Type) + +package ignored diff --git a/test/fixedbugs/issue4396a.go b/test/fixedbugs/issue4396a.go new file mode 100644 index 000000000..11ae1f7c6 --- /dev/null +++ b/test/fixedbugs/issue4396a.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4396. Arrays of bytes are not required to be +// word aligned. 5g should use MOVB to load the address +// of s.g[0] for its nil check. +// +// This test _may_ fail on arm, but requires the host to +// trap unaligned loads. This is generally done with +// +// echo "4" > /proc/cpu/alignment + +package main + +var s = struct { + // based on lzw.decoder + a, b, c, d, e uint16 + f [4096]uint8 + g [4096]uint8 +}{} + +func main() { + s.g[0] = 1 +} diff --git a/test/fixedbugs/issue4396b.go b/test/fixedbugs/issue4396b.go new file mode 100644 index 000000000..d0bf28fac --- /dev/null +++ b/test/fixedbugs/issue4396b.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This test _may_ fail on arm, but requires the host to +// trap unaligned loads. This is generally done with +// +// echo "4" > /proc/cpu/alignment + +package main + +type T struct { + U uint16 + V T2 +} + +type T2 struct { + pad [4096]byte + A, B byte +} + +var s, t = new(T), new(T) + +func main() { + var u, v *T2 = &s.V, &t.V + u.B = v.B +} diff --git a/test/fixedbugs/issue4399.go b/test/fixedbugs/issue4399.go new file mode 100644 index 000000000..6674db9ec --- /dev/null +++ b/test/fixedbugs/issue4399.go @@ -0,0 +1,15 @@ +// 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 4399: 8g would print "gins LEAQ nil *A". + +package main + +type A struct{ a int } + +func main() { + println(((*A)(nil)).a) +} diff --git a/test/fixedbugs/issue4405.go b/test/fixedbugs/issue4405.go new file mode 100644 index 000000000..c0d808559 --- /dev/null +++ b/test/fixedbugs/issue4405.go @@ -0,0 +1,15 @@ +// errorcheck + +// 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. + +package p + +const ( + _ = iota + _ // ERROR "illegal character" + _ // ERROR "illegal character" + _ // ERROR "illegal character" + _ // ERROR "illegal character" +) diff --git a/test/fixedbugs/issue4429.go b/test/fixedbugs/issue4429.go new file mode 100644 index 000000000..8a93b0204 --- /dev/null +++ b/test/fixedbugs/issue4429.go @@ -0,0 +1,16 @@ +// errorcheck + +// 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. + +package p + +type a struct { + a int +} + +func main() { + av := a{}; + *a(av); // ERROR "invalid indirect" +} diff --git a/test/fixedbugs/issue4448.go b/test/fixedbugs/issue4448.go new file mode 100644 index 000000000..fa1d9fe49 --- /dev/null +++ b/test/fixedbugs/issue4448.go @@ -0,0 +1,37 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4448: 64-bit indices that are statically known +// to be bounded make 5g and 8g generate a dangling branch. + +package main + +const b26 uint64 = 0x022fdd63cc95386d + +var bitPos [64]int + +func init() { + for p := uint(0); p < 64; p++ { + bitPos[b26<<p>>58] = int(p) + } +} + +func MinPos(w uint64) int { + if w == 0 { + panic("bit: MinPos(0) undefined") + } + return bitPos[((w&-w)*b26)>>58] +} + +func main() { + const one = uint64(1) + for i := 0; i < 64; i++ { + if MinPos(1<<uint(i)) != i { + println("i =", i) + panic("MinPos(1<<uint(i)) != i") + } + } +} diff --git a/test/fixedbugs/issue4452.go b/test/fixedbugs/issue4452.go new file mode 100644 index 000000000..c75da9024 --- /dev/null +++ b/test/fixedbugs/issue4452.go @@ -0,0 +1,13 @@ +// 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 4452. Used to print many errors, now just one. + +package main + +func main() { + _ = [...]int(4) // ERROR "use of \[\.\.\.\] array outside of array literal" +} diff --git a/test/fixedbugs/issue4458.go b/test/fixedbugs/issue4458.go new file mode 100644 index 000000000..8ee3e879e --- /dev/null +++ b/test/fixedbugs/issue4458.go @@ -0,0 +1,20 @@ +// errorcheck + +// 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 4458: gc accepts invalid method expressions +// like (**T).Method. + +package main + +type T struct{} + +func (T) foo() {} + +func main() { + av := T{} + pav := &av + (**T).foo(&pav) // ERROR "no method foo" +} diff --git a/test/fixedbugs/issue4463.go b/test/fixedbugs/issue4463.go new file mode 100644 index 000000000..fe07af71f --- /dev/null +++ b/test/fixedbugs/issue4463.go @@ -0,0 +1,87 @@ +// errorcheck + +// 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 4463: test builtin functions in statement context and in +// go/defer functions. + +package p + +import "unsafe" + +func F() { + var a []int + var c chan int + var m map[int]int + var s struct{ f int } + + append(a, 0) // ERROR "not used" + cap(a) // ERROR "not used" + complex(1, 2) // ERROR "not used" + imag(1i) // ERROR "not used" + len(a) // ERROR "not used" + make([]int, 10) // ERROR "not used" + new(int) // ERROR "not used" + real(1i) // ERROR "not used" + unsafe.Alignof(a) // ERROR "not used" + unsafe.Offsetof(s.f) // ERROR "not used" + unsafe.Sizeof(a) // ERROR "not used" + + 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 append(a, 0) // ERROR "discards result" + go cap(a) // ERROR "discards result" + go complex(1, 2) // ERROR "discards result" + go imag(1i) // ERROR "discards result" + go len(a) // ERROR "discards result" + go make([]int, 10) // ERROR "discards result" + go new(int) // ERROR "discards result" + go real(1i) // ERROR "discards result" + go unsafe.Alignof(a) // ERROR "discards result" + go unsafe.Offsetof(s.f) // ERROR "discards result" + go unsafe.Sizeof(a) // ERROR "discards result" + + go close(c) + go copy(a, a) + go delete(m, 0) + go panic(0) + go print("foo") + go println("bar") + go recover() + + defer append(a, 0) // ERROR "discards result" + defer cap(a) // ERROR "discards result" + defer complex(1, 2) // ERROR "discards result" + defer imag(1i) // ERROR "discards result" + defer len(a) // ERROR "discards result" + defer make([]int, 10) // ERROR "discards result" + defer new(int) // ERROR "discards result" + defer real(1i) // ERROR "discards result" + defer unsafe.Alignof(a) // ERROR "discards result" + defer unsafe.Offsetof(s.f) // ERROR "discards result" + defer unsafe.Sizeof(a) // ERROR "discards result" + + 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/issue4468.go b/test/fixedbugs/issue4468.go new file mode 100644 index 000000000..ef0b46bcf --- /dev/null +++ b/test/fixedbugs/issue4468.go @@ -0,0 +1,28 @@ +// errorcheck + +// 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 4468: go/defer calls may not be parenthesized. + +package p + +type T int + +func (t *T) F() T { + return *t +} + +type S struct { + t T +} + +func F() { + go (F()) // ERROR "must be function call" + defer (F()) // ERROR "must be function call" + var s S + (&s.t).F() + go (&s.t).F() + defer (&s.t).F() +} diff --git a/test/fixedbugs/issue4470.go b/test/fixedbugs/issue4470.go new file mode 100644 index 000000000..5ed09ca55 --- /dev/null +++ b/test/fixedbugs/issue4470.go @@ -0,0 +1,16 @@ +// errorcheck + +// 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 4470: parens are not allowed around .(type) "expressions" + +package main + +func main() { + var i interface{} + switch (i.(type)) { // ERROR "outside type switch" + default: + } +} diff --git a/test/fixedbugs/issue4495.go b/test/fixedbugs/issue4495.go new file mode 100644 index 000000000..7ec1134d7 --- /dev/null +++ b/test/fixedbugs/issue4495.go @@ -0,0 +1,29 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type I interface { + m() int +} + +type T struct{} + +func (T) m() int { + return 3 +} + +var t T + +var ret = I.m(t) + +func main() { + if ret != 3 { + println("ret = ", ret) + panic("ret != 3") + } +} + diff --git a/test/fixedbugs/issue4510.dir/f1.go b/test/fixedbugs/issue4510.dir/f1.go new file mode 100644 index 000000000..1e642e4ce --- /dev/null +++ b/test/fixedbugs/issue4510.dir/f1.go @@ -0,0 +1,9 @@ +// 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. + +package p + +import "fmt" // ERROR "fmt redeclared" + +var _ = fmt.Printf diff --git a/test/fixedbugs/issue4510.dir/f2.go b/test/fixedbugs/issue4510.dir/f2.go new file mode 100644 index 000000000..895fc342b --- /dev/null +++ b/test/fixedbugs/issue4510.dir/f2.go @@ -0,0 +1,7 @@ +// 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. + +package p + +func fmt() {} diff --git a/test/fixedbugs/issue4510.go b/test/fixedbugs/issue4510.go new file mode 100644 index 000000000..003f9e8e1 --- /dev/null +++ b/test/fixedbugs/issue4510.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// 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. + +package ignored diff --git a/test/fixedbugs/issue4517a.go b/test/fixedbugs/issue4517a.go new file mode 100644 index 000000000..a1b6b57e9 --- /dev/null +++ b/test/fixedbugs/issue4517a.go @@ -0,0 +1,9 @@ +// errorcheck + +// 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. + +package p + +var init = 1 // ERROR "cannot declare init - must be func" diff --git a/test/fixedbugs/issue4517b.go b/test/fixedbugs/issue4517b.go new file mode 100644 index 000000000..f04103ff5 --- /dev/null +++ b/test/fixedbugs/issue4517b.go @@ -0,0 +1,9 @@ +// errorcheck + +// 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. + +package p + +const init = 1 // ERROR "cannot declare init - must be func" diff --git a/test/fixedbugs/issue4517c.go b/test/fixedbugs/issue4517c.go new file mode 100644 index 000000000..47b21cf40 --- /dev/null +++ b/test/fixedbugs/issue4517c.go @@ -0,0 +1,9 @@ +// errorcheck + +// 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. + +package p + +type init byte // ERROR "cannot declare init - must be func" diff --git a/test/fixedbugs/issue4518.go b/test/fixedbugs/issue4518.go new file mode 100644 index 000000000..e64b069bb --- /dev/null +++ b/test/fixedbugs/issue4518.go @@ -0,0 +1,67 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4518. In some circumstances "return F(...)" +// where F has multiple returns is miscompiled by 6g due to +// bold assumptions in componentgen. + +package main + +func DontInline() {} + +func F(e interface{}) (int, int) { + DontInline() + return 3, 7 +} + +func G() (int, int) { + DontInline() + return 3, 7 +} + +func bogus1(d interface{}) (int, int) { + switch { + default: + return F(d) + } + return 0, 0 +} + +func bogus2() (int, int) { + switch { + default: + return F(3) + } + return 0, 0 +} + +func bogus3(d interface{}) (int, int) { + switch { + default: + return G() + } + return 0, 0 +} + +func bogus4() (int, int) { + switch { + default: + return G() + } + return 0, 0 +} + +func check(a, b int) { + if a != 3 || b != 7 { + println(a, b) + panic("a != 3 || b != 7") + } +} + +func main() { + check(bogus1(42)) + check(bogus2()) +} diff --git a/test/fixedbugs/issue4529.go b/test/fixedbugs/issue4529.go new file mode 100644 index 000000000..4f37e7c36 --- /dev/null +++ b/test/fixedbugs/issue4529.go @@ -0,0 +1,33 @@ +// 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 4529: escape analysis crashes on "go f(g())" +// when g has multiple returns. + +package main + +type M interface{} + +type A struct { + a string + b chan M +} + +func (a *A) I() (b <-chan M, c chan<- M) { + a.b, c = make(chan M), make(chan M) + b = a.b + + return +} + +func Init(a string, b *A, c interface { + I() (<-chan M, chan<- M) +}) { + b.a = a + go b.c(c.I()) +} + +func (a *A) c(b <-chan M, _ chan<- M) {} diff --git a/test/fixedbugs/issue4545.go b/test/fixedbugs/issue4545.go new file mode 100644 index 000000000..3f2de16d2 --- /dev/null +++ b/test/fixedbugs/issue4545.go @@ -0,0 +1,19 @@ +// errorcheck + +// 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 4545: untyped constants are incorrectly coerced +// to concrete types when used in interface{} context. + +package main + +import "fmt" + +func main() { + var s uint + fmt.Println(1.0 + 1<<s) // ERROR "invalid operation" + x := 1.0 + 1<<s // ERROR "invalid operation" + _ = x +} diff --git a/test/fixedbugs/issue4562.go b/test/fixedbugs/issue4562.go new file mode 100644 index 000000000..29d98b028 --- /dev/null +++ b/test/fixedbugs/issue4562.go @@ -0,0 +1,49 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "runtime" + "strings" +) + +type T struct { + val int +} + +func main() { + defer expectError(22) + var pT *T + switch pT.val { // error should be here - line 22 + case 0: + fmt.Println("0") + case 1: // used to show up here instead + fmt.Println("1") + case 2: + fmt.Println("2") + } + fmt.Println("finished") +} + +func expectError(expectLine int) { + if recover() == nil { + panic("did not crash") + } + for i := 1;; i++ { + _, file, line, ok := runtime.Caller(i) + if !ok { + panic("cannot find issue4562.go on stack") + } + if strings.HasSuffix(file, "issue4562.go") { + if line != expectLine { + panic(fmt.Sprintf("crashed at line %d, wanted line %d", line, expectLine)) + } + break + } + } +} diff --git a/test/fixedbugs/issue4585.go b/test/fixedbugs/issue4585.go new file mode 100644 index 000000000..ad1242d1e --- /dev/null +++ b/test/fixedbugs/issue4585.go @@ -0,0 +1,151 @@ +// 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 4585: comparisons and hashes process blank +// fields and padding in structs. + +package main + +import "unsafe" + +// T is a structure with padding. +type T struct { + A int16 + B int64 + C int16 + D int64 + Dummy [64]byte +} + +// U is a structure with a blank field +type U struct { + A, _, B int + Dummy [64]byte +} + +// USmall is like U but the frontend will inline comparison +// instead of calling the generated eq function. +type USmall struct { + A, _, B int32 +} + +// V has padding but not on the first field. +type V struct { + A1, A2, A3 int32 + B int16 + C int32 +} + +// W has padding at the end. +type W struct { + A1, A2, A3 int32 + B int32 + C int8 +} + +func test1() { + var a, b U + m := make(map[U]int) + copy((*[16]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B = 1, 2 + b.A, b.B = 1, 2 + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test2() { + var a, b T + m := make(map[T]int) + + copy((*[16]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B, a.C, a.D = 1, 2, 3, 4 + b.A, b.B, b.C, b.D = 1, 2, 3, 4 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test3() { + var a, b USmall + copy((*[12]byte)(unsafe.Pointer(&a))[:], "hello world!") + a.A, a.B = 1, 2 + b.A, b.B = 1, 2 + if a != b { + panic("broken equality: a != b") + } +} + +func test4() { + var a, b V + m := make(map[V]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test5() { + var a, b W + m := make(map[W]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func main() { + test1() + test2() + test3() + test4() + test5() +} diff --git a/test/fixedbugs/issue4590.dir/pkg1.go b/test/fixedbugs/issue4590.dir/pkg1.go new file mode 100644 index 000000000..c447371c1 --- /dev/null +++ b/test/fixedbugs/issue4590.dir/pkg1.go @@ -0,0 +1,26 @@ +// 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. + +package pkg1 + +type A interface { + Write() error +} + +type B interface { + Hello() + world() +} + +type C struct{} + +func (c C) Write() error { return nil } + +var T = struct{ A }{nil} +var U = struct{ B }{nil} +var V A = struct{ *C }{nil} +var W = interface { + Write() error + Hello() +}(nil) diff --git a/test/fixedbugs/issue4590.dir/pkg2.go b/test/fixedbugs/issue4590.dir/pkg2.go new file mode 100644 index 000000000..61c01d7ae --- /dev/null +++ b/test/fixedbugs/issue4590.dir/pkg2.go @@ -0,0 +1,15 @@ +// 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. + +package pkg2 + +import "./pkg1" + +var T = struct{ pkg1.A }{nil} +var U = struct{ pkg1.B }{nil} +var V pkg1.A = struct{ *pkg1.C }{nil} +var W = interface { + Write() error + Hello() +}(nil) diff --git a/test/fixedbugs/issue4590.dir/prog.go b/test/fixedbugs/issue4590.dir/prog.go new file mode 100644 index 000000000..3220e85d3 --- /dev/null +++ b/test/fixedbugs/issue4590.dir/prog.go @@ -0,0 +1,25 @@ +// 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. + +package main + +import ( + "./pkg1" + "./pkg2" +) + +func main() { + if pkg1.T != pkg2.T { + panic("pkg1.T != pkg2.T") + } + if pkg1.U != pkg2.U { + panic("pkg1.U != pkg2.U") + } + if pkg1.V != pkg2.V { + panic("pkg1.V != pkg2.V") + } + if pkg1.W != pkg2.W { + panic("pkg1.W != pkg2.W") + } +} diff --git a/test/fixedbugs/issue4590.go b/test/fixedbugs/issue4590.go new file mode 100644 index 000000000..faeb1adef --- /dev/null +++ b/test/fixedbugs/issue4590.go @@ -0,0 +1,10 @@ +// rundir + +// 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 4590: linker fails on multiple imports of +// an anonymous struct with methods. + +package ignored diff --git a/test/fixedbugs/issue4610.go b/test/fixedbugs/issue4610.go new file mode 100644 index 000000000..bc6bfe790 --- /dev/null +++ b/test/fixedbugs/issue4610.go @@ -0,0 +1,17 @@ +// errorcheck + +// 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. + +package main + +type bar struct { + x int +} + +func main() { + var foo bar + _ = &foo{} // ERROR "is not a type" +} + diff --git a/test/fixedbugs/issue4614.go b/test/fixedbugs/issue4614.go new file mode 100644 index 000000000..1aa318c2b --- /dev/null +++ b/test/fixedbugs/issue4614.go @@ -0,0 +1,20 @@ +// 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 4614: slicing of nil slices confuses the compiler +// with a uintptr(nil) node. + +package p + +import "unsafe" + +var n int + +var _ = []int(nil)[1:] +var _ = []int(nil)[n:] + +var _ = uintptr(unsafe.Pointer(nil)) +var _ = unsafe.Pointer(uintptr(0)) diff --git a/test/fixedbugs/issue4618.go b/test/fixedbugs/issue4618.go new file mode 100644 index 000000000..335feaadb --- /dev/null +++ b/test/fixedbugs/issue4618.go @@ -0,0 +1,40 @@ +// 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. + +package main + +import ( + "fmt" + "os" + "testing" +) + +type T struct { int } + +var globl *T + +func F() { + t := &T{} + globl = t +} + +func G() { + t := &T{} + _ = t +} + +func main() { + nf := testing.AllocsPerRun(100, F) + ng := testing.AllocsPerRun(100, G) + if int(nf) != 1 { + fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) + os.Exit(1) + } + if int(ng) != 0 { + fmt.Printf("AllocsPerRun(100, G) = %v, want 0\n", ng) + os.Exit(1) + } +} diff --git a/test/fixedbugs/issue4620.go b/test/fixedbugs/issue4620.go new file mode 100644 index 000000000..7b4ebf944 --- /dev/null +++ b/test/fixedbugs/issue4620.go @@ -0,0 +1,21 @@ +// 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 4620: map indexes are not evaluated before assignment of other elements + +package main + +import "fmt" + +func main() { + m := map[int]int{0:1} + i := 0 + i, m[i] = 1, 2 + if m[0] != 2 { + fmt.Println(m) + panic("m[i] != 2") + } +} diff --git a/test/fixedbugs/issue4654.go b/test/fixedbugs/issue4654.go new file mode 100644 index 000000000..170594e4b --- /dev/null +++ b/test/fixedbugs/issue4654.go @@ -0,0 +1,71 @@ +// 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 4654. +// Check error for conversion and 'not used' in defer/go. + +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" + + 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 copy(x, x) // ok + m := make(map[int]int) + defer delete(m, 1) // ok + defer panic(1) // ok + defer print(1) // ok + 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" + + append(x, 1) // ERROR "not used" + cap(x) // ERROR "not used" + complex(1, 2) // ERROR "not used" + complex(f, 1) // ERROR "not used" + imag(1i) // ERROR "not used" + imag(c) // ERROR "not used" + len(x) // ERROR "not used" + make([]int, 1) // ERROR "not used" + make(chan bool) // ERROR "not used" + make(map[string]int) // ERROR "not used" + new(int) // ERROR "not used" + real(1i) // ERROR "not used" + real(c) // ERROR "not used" + append(x, 1) // ERROR "not used" + append(x, 1) // ERROR "not used" + unsafe.Alignof(t.X) // ERROR "not used" + unsafe.Offsetof(t.X) // ERROR "not used" + unsafe.Sizeof(t) // ERROR "not used" +} diff --git a/test/fixedbugs/issue4663.go b/test/fixedbugs/issue4663.go new file mode 100644 index 000000000..b3d660287 --- /dev/null +++ b/test/fixedbugs/issue4663.go @@ -0,0 +1,14 @@ +// 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 4663. +// Make sure 'not used' message is placed correctly. + +package main + +func a(b int) int64 { + b // ERROR "not used" +} diff --git a/test/fixedbugs/issue4667.go b/test/fixedbugs/issue4667.go new file mode 100644 index 000000000..3a00a3195 --- /dev/null +++ b/test/fixedbugs/issue4667.go @@ -0,0 +1,37 @@ +// 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. + +package main + +import ( + "fmt" + "os" + "testing" +) + +var globl *int + +func G() { + F() +} + +func F() { + var x int + globl = &x +} + +func main() { + nf := testing.AllocsPerRun(100, F) + ng := testing.AllocsPerRun(100, G) + if int(nf) != 1 { + fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) + os.Exit(1) + } + if int(ng) != 1 { + fmt.Printf("AllocsPerRun(100, G) = %v, want 1\n", ng) + os.Exit(1) + } +} diff --git a/test/fixedbugs/issue4734.go b/test/fixedbugs/issue4734.go new file mode 100644 index 000000000..69f66f212 --- /dev/null +++ b/test/fixedbugs/issue4734.go @@ -0,0 +1,21 @@ +// 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. + +// Caused gccgo to emit multiple definitions of the same symbol. + +package p + +type S1 struct{} + +func (s *S1) M() {} + +type S2 struct { + F struct{ *S1 } +} + +func F() { + _ = struct{ *S1 }{} +} diff --git a/test/fixedbugs/issue4748.go b/test/fixedbugs/issue4748.go new file mode 100644 index 000000000..73c75393c --- /dev/null +++ b/test/fixedbugs/issue4748.go @@ -0,0 +1,20 @@ +// 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 4748. +// This program used to complain because inlining created two exit labels. + +package main + +func jump() { + goto exit +exit: + return +} +func main() { + jump() + jump() +} diff --git a/test/fixedbugs/issue4752.go b/test/fixedbugs/issue4752.go new file mode 100644 index 000000000..d6781e39a --- /dev/null +++ b/test/fixedbugs/issue4752.go @@ -0,0 +1,26 @@ +// 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. + +package main + +func F(xi, yi interface{}) uint64 { + x, y := xi.(uint64), yi.(uint64) + return x &^ y +} + +func G(xi, yi interface{}) uint64 { + return xi.(uint64) &^ yi.(uint64) // generates incorrect code +} + +func main() { + var x, y uint64 = 0, 1 << 63 + f := F(x, y) + g := G(x, y) + if f != 0 || g != 0 { + println("F", f, "G", g) + panic("bad") + } +} diff --git a/test/fixedbugs/issue4785.go b/test/fixedbugs/issue4785.go new file mode 100644 index 000000000..c3dd6297d --- /dev/null +++ b/test/fixedbugs/issue4785.go @@ -0,0 +1,20 @@ +// 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 4785: used to fail to compile + +package main + +func t(x, y interface{}) interface{} { + return x.(float64) > y.(float64) +} + +func main() { + v := t(1.0, 2.0) + if v != false { + panic("bad comparison") + } +} diff --git a/test/fixedbugs/issue4879.dir/a.go b/test/fixedbugs/issue4879.dir/a.go new file mode 100644 index 000000000..7ee7c4860 --- /dev/null +++ b/test/fixedbugs/issue4879.dir/a.go @@ -0,0 +1,33 @@ +package a + +import ( + "unsafe" +) + +type Collection struct { + root unsafe.Pointer +} + +type nodeLoc struct{} + +type slice []int + +type maptype map[int]int + +func MakePrivateCollection() *Collection { + return &Collection{ + root: unsafe.Pointer(&nodeLoc{}), + } +} + +func MakePrivateCollection2() *Collection { + return &Collection{ + root: unsafe.Pointer(&slice{}), + } +} +func MakePrivateCollection3() *Collection { + return &Collection{ + root: unsafe.Pointer(&maptype{}), + } +} + diff --git a/test/fixedbugs/issue4879.dir/b.go b/test/fixedbugs/issue4879.dir/b.go new file mode 100644 index 000000000..d8fb5693d --- /dev/null +++ b/test/fixedbugs/issue4879.dir/b.go @@ -0,0 +1,9 @@ +package b + +import "./a" + +func F() { + a.MakePrivateCollection() + a.MakePrivateCollection2() + a.MakePrivateCollection3() +} diff --git a/test/fixedbugs/issue4879.go b/test/fixedbugs/issue4879.go new file mode 100644 index 000000000..842c8117f --- /dev/null +++ b/test/fixedbugs/issue4879.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 4879: export data misses the '&' for some +// composite literals in inlined bodies. + +package ignored diff --git a/test/fixedbugs/issue4932.dir/foo.go b/test/fixedbugs/issue4932.dir/foo.go new file mode 100644 index 000000000..19b73a0e0 --- /dev/null +++ b/test/fixedbugs/issue4932.dir/foo.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 foo + +type Op struct{} diff --git a/test/fixedbugs/issue4932.dir/state.go b/test/fixedbugs/issue4932.dir/state.go new file mode 100644 index 000000000..c017b9649 --- /dev/null +++ b/test/fixedbugs/issue4932.dir/state.go @@ -0,0 +1,28 @@ +// 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 state + +import "./foo" + +func Public() { + var s Settings + s.op() +} + +type State struct{} + +func (s *State) x(*Settings) {} + +type Settings struct{} + +func (c *Settings) x() { + run([]foo.Op{{}}) +} + +func run([]foo.Op) {} + +func (s *Settings) op() foo.Op { + return foo.Op{} +} diff --git a/test/fixedbugs/issue4932.dir/state2.go b/test/fixedbugs/issue4932.dir/state2.go new file mode 100644 index 000000000..50f75db2c --- /dev/null +++ b/test/fixedbugs/issue4932.dir/state2.go @@ -0,0 +1,9 @@ +// 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 state2 + +import "./state" + +type Foo *state.State diff --git a/test/fixedbugs/issue4932.go b/test/fixedbugs/issue4932.go new file mode 100644 index 000000000..2a6bc699f --- /dev/null +++ b/test/fixedbugs/issue4932.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 4932: regression in export of composite literals. + +package ignored diff --git a/test/fixedbugs/issue887.go b/test/fixedbugs/issue887.go new file mode 100644 index 000000000..5bc193bf9 --- /dev/null +++ b/test/fixedbugs/issue887.go @@ -0,0 +1,36 @@ +// 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. + +// Used to leak registers on 8g. + +package p + +func f(x byte, y uint64) { + var r byte + switch y { + case 1: + r = x << y // '>>' triggers it too + case 2: + r = x << y + case 3: + r = x << y + case 4: + r = x << y + case 5: + r = x << y + case 6: + r = x << y + case 7: + r = x << y + case 8: + r = x << y + case 9: + r = x << y + case 10: + r = x << y + } + _ = r +} |