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 | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'test')
342 files changed, 7946 insertions, 905 deletions
diff --git a/test/64bit.go b/test/64bit.go index 9e91a97fd..d99d8e83f 100644 --- a/test/64bit.go +++ b/test/64bit.go @@ -1,6 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && -// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: 64bit -// rm -f tmp.go +// runoutput // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -596,6 +594,19 @@ const binaryConstR = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, "}\n" + "\n" +const binaryConstR0 = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {\n" + + " const b %v = %v;\n" + + " const typ = `%s`;\n" + + " if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + " if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + + "}\n" + + "\n" + const shiftConstL = "func test%vShiftL%v(b uint64, left, right %v) {\n" + " const a %v = %v;\n" + " const typ = `%s`;\n" + @@ -623,12 +634,20 @@ const shiftConstR = "func test%vShiftR%v(a, left, right %v) {\n" + func constTests() { for i, a := range int64Values { fmt.Fprintf(bout, binaryConstL, "Int64", i, "int64", "int64", a, "int64") - fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64") + if a.hi == 0 && a.lo == 0 { + fmt.Fprintf(bout, binaryConstR0, "Int64", i, "int64", "int64", a, "int64") + } else { + fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64") + } fmt.Fprintf(bout, shiftConstL, "Int64", i, "int64", "int64", a, "int64") } for i, a := range uint64Values { fmt.Fprintf(bout, binaryConstL, "Uint64", i, "uint64", "uint64", a, "uint64") - fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64") + if a.hi == 0 && a.lo == 0 { + fmt.Fprintf(bout, binaryConstR0, "Uint64", i, "uint64", "uint64", a, "uint64") + } else { + fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64") + } fmt.Fprintf(bout, shiftConstL, "Uint64", i, "uint64", "uint64", a, "uint64") } for i, a := range shiftValues { diff --git a/test/alias1.go b/test/alias1.go index 4219af8cd..42cf69340 100644 --- a/test/alias1.go +++ b/test/alias1.go @@ -17,7 +17,7 @@ func main() { case uint8: // ok default: - println("byte != uint8") + panic("byte != uint8") } x = uint8(2) @@ -25,7 +25,7 @@ func main() { case byte: // ok default: - println("uint8 != byte") + panic("uint8 != byte") } rune32 := false @@ -37,7 +37,7 @@ func main() { // must be new code rune32 = true default: - println("rune != int and rune != int32") + panic("rune != int and rune != int32") } if rune32 { @@ -49,6 +49,6 @@ func main() { case rune: // ok default: - println("int (or int32) != rune") + panic("int (or int32) != rune") } } diff --git a/test/args.go b/test/args.go index db624e9c2..0ffe8101e 100644 --- a/test/args.go +++ b/test/args.go @@ -1,4 +1,4 @@ -// $G $F.go && $L $F.$A && ./$A.out arg1 arg2 +// run arg1 arg2 // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/bench/garbage/parser.go b/test/bench/garbage/parser.go index d66281b6b..ff7630a9e 100644 --- a/test/bench/garbage/parser.go +++ b/test/bench/garbage/parser.go @@ -134,20 +134,31 @@ func main() { } } +// find . -type d -not -path "./exp" -not -path "./exp/*" -printf "\t\"%p\",\n" | sort | sed "s/\.\///" | grep -v testdata var packages = []string{ + "archive", "archive/tar", - "encoding/asn1", - "math/big", + "archive/zip", "bufio", + "builtin", "bytes", - "math/cmplx", + "compress", + "compress/bzip2", "compress/flate", "compress/gzip", + "compress/lzw", "compress/zlib", + "container", "container/heap", "container/list", "container/ring", + "crypto", "crypto/aes", + "crypto/cipher", + "crypto/des", + "crypto/dsa", + "crypto/ecdsa", + "crypto/elliptic", "crypto/hmac", "crypto/md5", "crypto/rand", @@ -159,66 +170,112 @@ var packages = []string{ "crypto/subtle", "crypto/tls", "crypto/x509", + "crypto/x509/pkix", + "database", + "database/sql", + "database/sql/driver", + "debug", "debug/dwarf", - "debug/macho", "debug/elf", "debug/gosym", - "exp/ebnf", + "debug/macho", + "debug/pe", + "encoding", "encoding/ascii85", + "encoding/asn1", + "encoding/base32", "encoding/base64", "encoding/binary", + "encoding/csv", + "encoding/gob", "encoding/hex", + "encoding/json", "encoding/pem", - "os/exec", + "encoding/xml", + "errors", + "expvar", "flag", "fmt", + "go", "go/ast", + "go/build", "go/doc", + "go/format", "go/parser", "go/printer", "go/scanner", "go/token", - "encoding/gob", + "go/types", "hash", "hash/adler32", "hash/crc32", "hash/crc64", - "net/http", + "hash/fnv", + "html", + "html/template", "image", + "image/color", + "image/draw", + "image/gif", "image/jpeg", "image/png", + "index", + "index/suffixarray", "io", "io/ioutil", - "encoding/json", "log", + "log/syslog", "math", + "math/big", + "math/cmplx", + "math/rand", "mime", + "mime/multipart", "net", + "net/http", + "net/http/cgi", + "net/http/cookiejar", + "net/http/fcgi", + "net/http/httptest", + "net/http/httputil", + "net/http/pprof", + "net/mail", + "net/rpc", + "net/rpc/jsonrpc", + "net/smtp", + "net/textproto", + "net/url", "os", - "exp/signal", + "os/exec", + "os/signal", + "os/user", "path", - "math/rand", + "path/filepath", "reflect", "regexp", - "net/rpc", + "regexp/syntax", "runtime", - "text/scanner", + "runtime/cgo", + "runtime/debug", + "runtime/pprof", + "runtime/race", "sort", - "net/smtp", "strconv", "strings", "sync", + "sync/atomic", "syscall", - "log/syslog", - "text/tabwriter", - "text/template", "testing", "testing/iotest", "testing/quick", - "testing/script", + "text", + "text/scanner", + "text/tabwriter", + "text/template", + "text/template/parse", "time", "unicode", - "unicode/utf8", "unicode/utf16", - "encoding/xml", + "unicode/utf8", + "unsafe", } diff --git a/test/bench/garbage/stats.go b/test/bench/garbage/stats.go index cdcb32f9b..6dc0aeb23 100644 --- a/test/bench/garbage/stats.go +++ b/test/bench/garbage/stats.go @@ -14,16 +14,21 @@ import ( func gcstats(name string, n int, t time.Duration) { st := new(runtime.MemStats) runtime.ReadMemStats(st) - fmt.Printf("garbage.%sMem Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs) - fmt.Printf("garbage.%s %d %d ns/op\n", name, n, t.Nanoseconds()/int64(n)) - fmt.Printf("garbage.%sLastPause 1 %d ns/op\n", name, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))]) - fmt.Printf("garbage.%sPause %d %d ns/op\n", name, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC)) + nprocs := runtime.GOMAXPROCS(-1) + cpus := "" + if nprocs != 1 { + cpus = fmt.Sprintf("-%d", nprocs) + } + fmt.Printf("garbage.%sMem%s Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, cpus, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs) + fmt.Printf("garbage.%s%s %d %d ns/op\n", name, cpus, n, t.Nanoseconds()/int64(n)) + fmt.Printf("garbage.%sLastPause%s 1 %d ns/op\n", name, cpus, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))]) + fmt.Printf("garbage.%sPause%s %d %d ns/op\n", name, cpus, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC)) nn := int(st.NumGC) if nn >= len(st.PauseNs) { nn = len(st.PauseNs) } t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn]) - fmt.Printf("garbage.%sPause5: %d %d %d %d %d\n", name, t1, t2, t3, t4, t5) + fmt.Printf("garbage.%sPause5%s: %d %d %d %d %d\n", name, cpus, t1, t2, t3, t4, t5) // fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist) } diff --git a/test/bench/garbage/tree2.go b/test/bench/garbage/tree2.go index 3db0a0ba3..a171c696b 100644 --- a/test/bench/garbage/tree2.go +++ b/test/bench/garbage/tree2.go @@ -11,6 +11,7 @@ import ( "os" "runtime" "runtime/pprof" + "time" "unsafe" ) @@ -83,7 +84,12 @@ func main() { pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } - for i := 0; i < 10; i++ { + const N = 10 + var t0 time.Time + for i := 0; i < N; i++ { + t0 = time.Now() gc() } + // Standard gotest benchmark output, collected by build dashboard. + gcstats("BenchmarkTree2", N, time.Now().Sub(t0)) } diff --git a/test/bench/go1/fasta_test.go b/test/bench/go1/fasta_test.go index dcb2d1055..bff056fa9 100644 --- a/test/bench/go1/fasta_test.go +++ b/test/bench/go1/fasta_test.go @@ -4,9 +4,24 @@ package go1 +import "runtime" + // Not a benchmark; input for revcomp. -var fasta25m = fasta(25e6) +var fastabytes = makefasta() + +func makefasta() []byte { + var n int = 25e6 + if runtime.GOARCH == "arm" { + // TODO(dfc) remove this limitation after precise gc. + // A value of 25e6 consumes 465mb of heap on 32bit + // platforms, which is too much for most ARM systems. + // A value of 25e5 produces a memory layout that + // confuses the gc on 32bit platforms. So 25e4 it is. + n = 25e4 + } + return fasta(n) +} func fasta(n int) []byte { out := make(fastaBuffer, 0, 11*n) diff --git a/test/bench/go1/gob_test.go b/test/bench/go1/gob_test.go index 00eeed57a..b172b805a 100644 --- a/test/bench/go1/gob_test.go +++ b/test/bench/go1/gob_test.go @@ -21,9 +21,7 @@ var ( gobdata *JSONResponse ) -func gobinit() { - // gobinit is called after json's init, - // because it uses jsondata. +func init() { gobdata = gobResponse(&jsondata) var buf bytes.Buffer diff --git a/test/bench/go1/json_test.go b/test/bench/go1/json_test.go index 5a3012167..614e24a81 100644 --- a/test/bench/go1/json_test.go +++ b/test/bench/go1/json_test.go @@ -17,11 +17,11 @@ import ( ) var ( - jsonbytes []byte - jsondata JSONResponse + jsonbytes = makeJsonBytes() + jsondata = makeJsonData() ) -func init() { +func makeJsonBytes() []byte { var r io.Reader r = strings.NewReader(jsonbz2_base64) r = base64.NewDecoder(base64.StdEncoding, r) @@ -30,12 +30,15 @@ func init() { if err != nil { panic(err) } - jsonbytes = b + return b +} - if err := json.Unmarshal(jsonbytes, &jsondata); err != nil { +func makeJsonData() JSONResponse { + var v JSONResponse + if err := json.Unmarshal(jsonbytes, &v); err != nil { panic(err) } - gobinit() + return v } type JSONResponse struct { diff --git a/test/bench/go1/mandel_test.go b/test/bench/go1/mandel_test.go new file mode 100644 index 000000000..888c5e4ea --- /dev/null +++ b/test/bench/go1/mandel_test.go @@ -0,0 +1,41 @@ +// 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 benchmark, taken from the shootuot, tests floating point performance. + +package go1 + +import "testing" + +func mandelbrot(n int) int { + const Iter = 50 + const Zero float64 = 0 + const Limit = 2.0 + ok := 0 + for y := 0; y < n; y++ { + for x := 0; x < n; x++ { + Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero + Cr := (2*float64(x)/float64(n) - 1.5) + Ci := (2*float64(y)/float64(n) - 1.0) + + for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ { + Zi = 2*Zr*Zi + Ci + Zr = Tr - Ti + Cr + Tr = Zr * Zr + Ti = Zi * Zi + } + + if Tr+Ti <= Limit*Limit { + ok++ + } + } + } + return ok +} + +func BenchmarkMandelbrot200(b *testing.B) { + for i := 0; i < b.N; i++ { + mandelbrot(200) + } +} diff --git a/test/bench/go1/parser_test.go b/test/bench/go1/parser_test.go new file mode 100644 index 000000000..26580b887 --- /dev/null +++ b/test/bench/go1/parser_test.go @@ -0,0 +1,43 @@ +// 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 go1 + +// go parser benchmark based on go/parser/performance_test.go + +import ( + "compress/bzip2" + "encoding/base64" + "go/parser" + "go/token" + "io" + "io/ioutil" + "strings" + "testing" +) + +var ( + parserbytes = makeParserBytes() +) + +func makeParserBytes() []byte { + var r io.Reader + r = strings.NewReader(parserbz2_base64) + r = base64.NewDecoder(base64.StdEncoding, r) + r = bzip2.NewReader(r) + b, err := ioutil.ReadAll(r) + if err != nil { + panic(err) + } + return b +} + +func BenchmarkParse(b *testing.B) { + b.SetBytes(int64(len(parserbytes))) + for i := 0; i < b.N; i++ { + if _, err := parser.ParseFile(token.NewFileSet(), "", parserbytes, parser.ParseComments); err != nil { + b.Fatalf("benchmark failed due to parse error: %s", err) + } + } +} diff --git a/test/bench/go1/parserdata_test.go b/test/bench/go1/parserdata_test.go new file mode 100644 index 000000000..113e5e3e3 --- /dev/null +++ b/test/bench/go1/parserdata_test.go @@ -0,0 +1,245 @@ +// 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. + +// Input for parser benchmark. +// This was generated by starting with a the contents of +// src/pkg/go/parser/parser.go at rev 9b455eb64690, then +// compressing with bzip2 -9, then encoding to base64. +// We compile the data into the binary so that the benchmark is +// a stand-alone binary that can be copied easily from machine to +// machine. parser_test.go decodes this during init. + +package go1 + +var parserbz2_base64 = "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" + + "v9hdyRThQkN3QmOE" diff --git a/test/bench/go1/revcomp_test.go b/test/bench/go1/revcomp_test.go index 9256164d7..6b6c1e577 100644 --- a/test/bench/go1/revcomp_test.go +++ b/test/bench/go1/revcomp_test.go @@ -77,9 +77,9 @@ func revcomp(data []byte) { } } -func BenchmarkRevcomp25M(b *testing.B) { - b.SetBytes(int64(len(fasta25m))) +func BenchmarkRevcomp(b *testing.B) { + b.SetBytes(int64(len(fastabytes))) for i := 0; i < b.N; i++ { - revcomp(fasta25m) + revcomp(fastabytes) } } diff --git a/test/bench/shootout/binary-tree.c b/test/bench/shootout/binary-tree.c index 1b4070406..9c35ac52a 100644 --- a/test/bench/shootout/binary-tree.c +++ b/test/bench/shootout/binary-tree.c @@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE. icc -O3 -ip -unroll -static binary-trees.c -lm */ -#include <malloc.h> #include <math.h> #include <stdio.h> #include <stdlib.h> diff --git a/test/bench/shootout/k-nucleotide.c b/test/bench/shootout/k-nucleotide.c index 3bace391c..9c3062020 100644 --- a/test/bench/shootout/k-nucleotide.c +++ b/test/bench/shootout/k-nucleotide.c @@ -221,7 +221,7 @@ main () free(s); - g_ptr_array_foreach(roots, free, NULL); + g_ptr_array_foreach(roots, (GFunc)free, NULL); g_ptr_array_free(roots, TRUE); return 0; diff --git a/test/bench/shootout/mandelbrot.go b/test/bench/shootout/mandelbrot.go index 1f9fbfd3d..df60343c2 100644 --- a/test/bench/shootout/mandelbrot.go +++ b/test/bench/shootout/mandelbrot.go @@ -50,21 +50,21 @@ func main() { out := bufio.NewWriter(os.Stdout) defer out.Flush() - w := *n - h := *n + w := float64(*n) + h := float64(*n) bit_num := 0 byte_acc := byte(0) const Iter = 50 const Zero float64 = 0 const Limit = 2.0 - fmt.Fprintf(out, "P4\n%d %d\n", w, h) + fmt.Fprintf(out, "P4\n%d %d\n", *n, *n) - for y := 0; y < h; y++ { - for x := 0; x < w; x++ { + for y := 0.0; y < h; y++ { + for x := 0.0; x < w; x++ { Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero - Cr := (2*float64(x)/float64(w) - 1.5) - Ci := (2*float64(y)/float64(h) - 1.0) + Cr := (2*x/w - 1.5) + Ci := (2*y/h - 1.0) for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ { Zi = 2*Zr*Zi + Ci @@ -85,7 +85,7 @@ func main() { byte_acc = 0 bit_num = 0 } else if x == w-1 { - byte_acc <<= uint(8 - w%8) + byte_acc <<= uint(8 - uint(*n)%8) out.WriteByte(byte_acc) byte_acc = 0 bit_num = 0 diff --git a/test/bench/shootout/threadring.c b/test/bench/shootout/threadring.c index 2c4fb7751..a518134ba 100644 --- a/test/bench/shootout/threadring.c +++ b/test/bench/shootout/threadring.c @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. * contributed by Premysl Hruby */ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <pthread.h> @@ -57,7 +58,7 @@ static struct stack stacks[THREADS]; static void* thread(void *num) { - int l = (int)num; + int l = (int)(uintptr_t)num; int r = (l+1) % THREADS; int token; @@ -94,7 +95,7 @@ int main(int argc, char **argv) pthread_mutex_lock(mutex + i); pthread_attr_setstack(&stack_attr, &stacks[i], sizeof(struct stack)); - pthread_create(&cthread, &stack_attr, thread, (void*)i); + pthread_create(&cthread, &stack_attr, thread, (void*)(uintptr_t)i); } pthread_mutex_unlock(mutex + 0); diff --git a/test/bench/shootout/timing.log b/test/bench/shootout/timing.log index 2541a766b..ee1f889b4 100644 --- a/test/bench/shootout/timing.log +++ b/test/bench/shootout/timing.log @@ -900,3 +900,264 @@ threadring 50000000 chameneos 6000000 gc chameneosredux 7.41u 0.00s 7.42r # -3% + +# A complete run at the Go 1 release. +# Significant changes: +# - gccgo is now enabled for all tests (goroutines are cheap enough) +# - threadring and chameneos are 14% faster, probably due to runtime changes +# - regex-dna 36% faster +# - fannkuch-parallel (only) slowed down 40% +# - gccgo on binary-tree-freelist is still optimized to nothing +# Other changes are modest. + +fasta -n 25000000 + gcc -O2 fasta.c 1.45u 0.02s 1.48r + gccgo -O2 fasta.go 1.46u 0.00s 1.47r + gc fasta 1.99u 0.01s 2.00r + gc_B fasta 1.99u 0.01s 2.01r + +reverse-complement < output-of-fasta-25000000 + gcc -O2 reverse-complement.c 0.95u 0.48s 4.99r + gccgo -O2 reverse-complement.go 0.93u 0.16s 1.09r + gc reverse-complement 1.20u 0.19s 1.39r + gc_B reverse-complement 1.04u 0.16s 1.20r + +nbody -n 50000000 + gcc -O2 -lm nbody.c 13.02u 0.00s 13.05r + gccgo -O2 nbody.go 14.46u 0.00s 14.49r + gc nbody 21.79u 0.00s 21.84r + gc_B nbody 21.74u 0.00s 21.79r + +binary-tree 15 # too slow to use 20 + gcc -O2 binary-tree.c -lm 0.60u 0.01s 0.61r + gccgo -O2 binary-tree.go 1.30u 0.01s 1.32r + gccgo -O2 binary-tree-freelist.go 0.00u 0.00s 0.00r + gc binary-tree 1.84u 0.01s 1.86r + gc binary-tree-freelist 0.33u 0.00s 0.33r + +fannkuch 12 + gcc -O2 fannkuch.c 45.24u 0.00s 45.34r + gccgo -O2 fannkuch.go 59.76u 0.01s 59.90r + gccgo -O2 fannkuch-parallel.go 218.20u 0.01s 61.60r + gc fannkuch 103.92u 0.00s 104.16r + gc fannkuch-parallel 221.61u 0.00s 60.49r + gc_B fannkuch 53.17u 0.00s 53.30r + +regex-dna 100000 + gcc -O2 regex-dna.c -lpcre 0.47u 0.00s 0.48r + gccgo -O2 regex-dna.go 6.52u 0.00s 6.54r + gccgo -O2 regex-dna-parallel.go 14.40u 0.73s 4.35r + gc regex-dna 2.63u 0.02s 2.66r # -36% + gc regex-dna-parallel 2.87u 0.01s 1.11r + gc_B regex-dna 2.65u 0.00s 2.66r + +spectral-norm 5500 + gcc -O2 spectral-norm.c -lm 15.78u 0.00s 15.82r + gccgo -O2 spectral-norm.go 15.79u 0.00s 15.83r + gc spectral-norm 19.76u 0.00s 19.80r + gc_B spectral-norm 19.73u 0.01s 19.78r + +k-nucleotide 1000000 + gcc -O2 k-nucleotide.c 5.59u 0.03s 5.63r + gccgo -O2 k-nucleotide.go 4.09u 0.03s 4.13r + gccgo -O2 k-nucleotide-parallel.go 4.50u 0.06s 1.63r + gc k-nucleotide 9.23u 0.02s 9.27r + gc k-nucleotide-parallel 9.87u 0.03s 3.55r + gc_B k-nucleotide 9.20u 0.00s 9.22r + +mandelbrot 16000 + gcc -O2 mandelbrot.c 36.09u 0.00s 36.18r + gccgo -O2 mandelbrot.go 41.69u 0.01s 41.80r + gc mandelbrot 60.91u 0.02s 61.07r + gc_B mandelbrot 60.90u 0.00s 61.04r + +meteor 2098 + gcc -O2 meteor-contest.c 0.09u 0.00s 0.09r + gccgo -O2 meteor-contest.go 0.09u 0.00s 0.09r + gc meteor-contest 0.14u 0.00s 0.15r + gc_B meteor-contest 0.14u 0.00s 0.14r + +pidigits 10000 + gcc -O2 pidigits.c -lgmp 2.27u 0.00s 2.27r + gccgo -O2 pidigits.go 8.65u 0.00s 8.67r + gc pidigits 3.70u 0.04s 3.75r + gc_B pidigits 3.72u 0.02s 3.75r + +threadring 50000000 + gcc -O2 threadring.c 40.91u 369.85s 323.31r + gccgo -O2 threadring.go 26.97u 30.82s 57.93r + gc threadring 12.81u 0.01s 12.85r # -13% + +chameneos 6000000 + gcc -O2 chameneosredux.c -lpthread 9.44u 72.90s 12.65r + gccgo -O2 chameneosredux.go 7.73u 7.53s 15.30r + gc chameneosredux 6.51u 0.00s 6.53r # - 14% + +# After http://codereview.appspot.com/6248049, moving panicindex +# calls out of line (putting the likely code into a single path and shortening +# loops). Significant changes since the last run (note: some are slower for +# unrelated and as yet undiagnosed reasons): + +nbody -n 50000000 + gc nbody 19.10u 0.01s 19.19r # -12% + gc_B nbody 19.19u 0.00s 19.23r # -12% + +binary-tree 15 # too slow to use 20 + gc binary-tree 1.49u 0.01s 1.51r # -19% + +fannkuch 12 + gc fannkuch 60.79u 0.00s 60.92r # -41% + gc fannkuch-parallel 183.51u 0.01s 51.75r # -14% + gc_B fannkuch 51.68u 0.00s 51.79r # -3% + +k-nucleotide 1000000 + gc k-nucleotide 9.74u 0.04s 9.80r # +6% + gc k-nucleotide-parallel 9.89u 0.05s 3.59r # +1% + gc_B k-nucleotide 9.39u 0.02s 9.43r # +2% + +mandelbrot (much slower, due to unrelated http://codereview.appspot.com/6209077) + gc mandelbrot 100.98u 0.00s 101.20r # +65% + gc_B mandelbrot 100.90u 0.01s 101.17r # +65% + +meteor 2098 + gc meteor-contest 0.13u 0.00s 0.13r # -13% + gc_B meteor-contest 0.13u 0.00s 0.13r # -7% + +# May 30, 2012. +# After http://codereview.appspot.com/6261051, restoring old code generated +# for floating-point constants. Mandelbrot is back to its previous numbers. + +mandelbrot 16000 + gcc -O2 mandelbrot.c 36.07u 0.00s 36.16r + gccgo -O2 mandelbrot.go 41.72u 0.01s 41.90r + gc mandelbrot 60.62u 0.00s 60.76r + gc_B mandelbrot 60.68u 0.00s 60.82r + +# May 30, 2012. +# After http://codereview.appspot.com/6248068, better FP code +# by avoiding MOVSD between registers. +# Plus some other timing changes that have crept in from other speedups, +# from garbage collection to Printf. + +fasta -n 25000000 + gc fasta 1.76u 0.00s 1.76r # -12% + gc_B fasta 1.71u 0.00s 1.72r # -12% + +nbody -n 50000000 + gc nbody 17.56u 0.00s 17.60r # -8% + gc_B nbody 17.30u 0.00s 17.34r # -10% + +fannkuch 12 + gc fannkuch-parallel 155.92u 0.01s 44.05r # -15% + +k-nucleotide 1000000 + gc k-nucleotide 9.22u 0.01s 9.26r # -5% + gc k-nucleotide-parallel 9.23u 0.03s 3.26r # -9% + gc_B k-nucleotide 9.22u 0.03s 9.28r # -2% + +mandelbrot 16000 + gc mandelbrot 44.80u 0.00s 44.90r # -27% + gc_B mandelbrot 44.81u 0.00s 44.92r # -26% + +pidigits 10000 + gc pidigits 3.51u 0.00s 3.52r # -6% + gc_B pidigits 3.51u 0.00s 3.52r # -6% + +# Aug 28, 2012 +# After some assembler work in package big. +pidigits 10000 + gc pidigits 2.85u 0.02s 2.88r # -22% + gc_B pidigits 2.88u 0.01s 2.90r # -21% + +# Sep 26, 2012 +# 64-bit ints, plus significantly better floating-point code. +# Interesting details: +# Generally something in the 0-10% slower range, some (binary tree) more +# Floating-point noticeably faster: +# nbody -25% +# mandelbrot -37% relative to Go 1. +# Other: +# regex-dna +47% +fasta -n 25000000 + gcc -O2 fasta.c 1.43u 0.03s 1.46r + gccgo -O2 fasta.go 1.47u 0.00s 1.47r + gc fasta 1.78u 0.01s 1.80r + gc_B fasta 1.76u 0.00s 1.76r + +reverse-complement < output-of-fasta-25000000 + gcc -O2 reverse-complement.c 1.14u 0.39s 11.19r + gccgo -O2 reverse-complement.go 0.91u 0.17s 1.09r + gc reverse-complement 1.12u 0.18s 1.31r + gc_B reverse-complement 1.12u 0.15s 1.28r + +nbody -n 50000000 + gcc -O2 nbody.c -lm 13.02u 0.00s 13.05r + gccgo -O2 nbody.go 13.90u 0.00s 13.93r + gc nbody 17.05u 0.00s 17.09r + gc_B nbody 16.30u 0.00s 16.34r + +binary-tree 15 # too slow to use 20 + gcc -O2 binary-tree.c -lm 0.61u 0.00s 0.61r + gccgo -O2 binary-tree.go 1.24u 0.04s 1.29r + gccgo -O2 binary-tree-freelist.go 0.21u 0.01s 0.22r + gc binary-tree 1.93u 0.02s 1.96r + gc binary-tree-freelist 0.32u 0.00s 0.33r + +fannkuch 12 + gcc -O2 fannkuch.c 45.19u 0.00s 45.29r + gccgo -O2 fannkuch.go 60.32u 0.00s 60.45r + gccgo -O2 fannkuch-parallel.go 185.59u 0.00s 59.49r + gc fannkuch 72.14u 0.00s 72.30r + gc fannkuch-parallel 172.54u 0.00s 43.59r + gc_B fannkuch 53.55u 0.00s 53.67r + +regex-dna 100000 + gcc -O2 regex-dna.c -lpcre 0.47u 0.00s 0.47r + gccgo -O2 regex-dna.go 6.49u 0.05s 6.56r + gccgo -O2 regex-dna-parallel.go 14.60u 0.67s 4.42r + gc regex-dna 3.91u 0.00s 3.92r + gc regex-dna-parallel 4.01u 0.03s 1.56r + gc_B regex-dna 3.91u 0.00s 3.92r + +spectral-norm 5500 + gcc -O2 spectral-norm.c -lm 15.85u 0.00s 15.89r + gccgo -O2 spectral-norm.go 15.86u 0.00s 15.89r + gc spectral-norm 19.72u 0.00s 19.76r + gc_B spectral-norm 19.68u 0.01s 19.74r + +k-nucleotide 1000000 + gcc -O2 k-nucleotide.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 4.90u 0.01s 4.93r + gccgo -O2 k-nucleotide.go 4.78u 0.01s 4.80r + gccgo -O2 k-nucleotide-parallel.go 6.49u 0.02s 2.18r + gc k-nucleotide 9.05u 0.02s 9.09r + gc k-nucleotide-parallel 9.27u 0.01s 3.29r + gc_B k-nucleotide 8.95u 0.03s 9.00r + +mandelbrot 16000 + gcc -O2 mandelbrot.c 36.11u 0.00s 36.19r + gccgo -O2 mandelbrot.go 43.67u 0.00s 43.77r + gc mandelbrot 38.57u 0.00s 38.66r + gc_B mandelbrot 38.59u 0.00s 38.68r + +meteor 2098 + gcc -O2 meteor-contest.c 0.09u 0.00s 0.09r + gccgo -O2 meteor-contest.go 0.09u 0.00s 0.09r + gc meteor-contest 0.13u 0.00s 0.14r + gc_B meteor-contest 0.12u 0.00s 0.13r + +pidigits 10000 + gcc -O2 pidigits.c -lgmp 2.26u 0.00s 2.27r + gccgo -O2 pidigits.go 9.05u 0.00s 9.07r + gc pidigits 2.88u 0.02s 2.90r + gc_B pidigits 2.89u 0.00s 2.90r + +threadring 50000000 + gcc -O2 threadring.c -lpthread 37.30u 327.81s 289.28r + gccgo -O2 threadring.go 42.83u 26.15s 69.14r + gc threadring 13.00u 0.00s 13.03r + +chameneos 6000000 + gcc -O2 chameneosredux.c -lpthread 8.80u 71.67s 12.19r + gccgo -O2 chameneosredux.go 11.28u 6.68s 18.00r + gc chameneosredux 6.94u 0.00s 6.96r + diff --git a/test/bench/shootout/timing.sh b/test/bench/shootout/timing.sh index dd3e664f4..2db895c26 100755 --- a/test/bench/shootout/timing.sh +++ b/test/bench/shootout/timing.sh @@ -10,6 +10,14 @@ O=$GOCHAR GC="go tool ${O}g" LD="go tool ${O}l" +gccm="" +case "$O" in +8) + gccm=-m32;; +6) + gccm=-m64;; +esac + PATH=.:$PATH havegccgo=false @@ -78,7 +86,7 @@ run() { fasta() { runonly echo 'fasta -n 25000000' - run 'gcc -O2 fasta.c' a.out 25000000 + run "gcc $gccm -O2 fasta.c" a.out 25000000 run 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio run 'gc fasta' $O.out -n 25000000 run 'gc_B fasta' $O.out -n 25000000 @@ -88,7 +96,7 @@ revcomp() { runonly gcc -O2 fasta.c runonly a.out 25000000 > x runonly echo 'reverse-complement < output-of-fasta-25000000' - run 'gcc -O2 reverse-complement.c' a.out < x + run "gcc $gccm -O2 reverse-complement.c" a.out < x run 'gccgo -O2 reverse-complement.go' a.out < x run 'gc reverse-complement' $O.out < x run 'gc_B reverse-complement' $O.out < x @@ -97,7 +105,7 @@ revcomp() { nbody() { runonly echo 'nbody -n 50000000' - run 'gcc -O2 -lm nbody.c' a.out 50000000 + run "gcc $gccm -O2 nbody.c -lm" a.out 50000000 run 'gccgo -O2 nbody.go' a.out -n 50000000 run 'gc nbody' $O.out -n 50000000 run 'gc_B nbody' $O.out -n 50000000 @@ -105,16 +113,16 @@ nbody() { binarytree() { runonly echo 'binary-tree 15 # too slow to use 20' - run 'gcc -O2 binary-tree.c -lm' a.out 15 + run "gcc $gccm -O2 binary-tree.c -lm" a.out 15 run 'gccgo -O2 binary-tree.go' a.out -n 15 - run 'gccgo -O2 binary-tree-freelist.go' $O.out -n 15 + run 'gccgo -O2 binary-tree-freelist.go' a.out -n 15 run 'gc binary-tree' $O.out -n 15 run 'gc binary-tree-freelist' $O.out -n 15 } fannkuch() { runonly echo 'fannkuch 12' - run 'gcc -O2 fannkuch.c' a.out 12 + run "gcc $gccm -O2 fannkuch.c" a.out 12 run 'gccgo -O2 fannkuch.go' a.out -n 12 run 'gccgo -O2 fannkuch-parallel.go' a.out -n 12 run 'gc fannkuch' $O.out -n 12 @@ -126,7 +134,7 @@ regexdna() { runonly gcc -O2 fasta.c runonly a.out 100000 > x runonly echo 'regex-dna 100000' - run 'gcc -O2 regex-dna.c -lpcre' a.out <x + run "gcc $gccm -O2 regex-dna.c -lpcre" a.out <x run 'gccgo -O2 regex-dna.go' a.out <x run 'gccgo -O2 regex-dna-parallel.go' a.out <x run 'gc regex-dna' $O.out <x @@ -137,7 +145,7 @@ regexdna() { spectralnorm() { runonly echo 'spectral-norm 5500' - run 'gcc -O2 spectral-norm.c -lm' a.out 5500 + run "gcc $gccm -O2 spectral-norm.c -lm" a.out 5500 run 'gccgo -O2 spectral-norm.go' a.out -n 5500 run 'gc spectral-norm' $O.out -n 5500 run 'gc_B spectral-norm' $O.out -n 5500 @@ -147,7 +155,9 @@ knucleotide() { runonly gcc -O2 fasta.c runonly a.out 1000000 > x # should be using 25000000 runonly echo 'k-nucleotide 1000000' - run 'gcc -O2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include k-nucleotide.c -lglib-2.0' a.out <x + if [ $mode = run ]; then + run "gcc -O2 k-nucleotide.c $(pkg-config glib-2.0 --cflags --libs)" a.out <x + fi run 'gccgo -O2 k-nucleotide.go' a.out <x run 'gccgo -O2 k-nucleotide-parallel.go' a.out <x run 'gc k-nucleotide' $O.out <x @@ -158,7 +168,7 @@ knucleotide() { mandelbrot() { runonly echo 'mandelbrot 16000' - run 'gcc -O2 mandelbrot.c' a.out 16000 + run "gcc $gccm -O2 mandelbrot.c" a.out 16000 run 'gccgo -O2 mandelbrot.go' a.out -n 16000 run 'gc mandelbrot' $O.out -n 16000 run 'gc_B mandelbrot' $O.out -n 16000 @@ -166,7 +176,7 @@ mandelbrot() { meteor() { runonly echo 'meteor 2098' - run 'gcc -O2 meteor-contest.c' a.out 2098 + run "gcc $gccm -O2 meteor-contest.c" a.out 2098 run 'gccgo -O2 meteor-contest.go' a.out -n 2098 run 'gc meteor-contest' $O.out -n 2098 run 'gc_B meteor-contest' $O.out -n 2098 @@ -174,7 +184,7 @@ meteor() { pidigits() { runonly echo 'pidigits 10000' - run 'gcc -O2 pidigits.c -lgmp' a.out 10000 + run "gcc $gccm -O2 pidigits.c -lgmp" a.out 10000 run 'gccgo -O2 pidigits.go' a.out -n 10000 run 'gc pidigits' $O.out -n 10000 run 'gc_B pidigits' $O.out -n 10000 @@ -182,14 +192,14 @@ pidigits() { threadring() { runonly echo 'threadring 50000000' - run 'gcc -O2 threadring.c -lpthread' a.out 50000000 + run "gcc $gccm -O2 threadring.c -lpthread" a.out 50000000 run 'gccgo -O2 threadring.go' a.out -n 50000000 run 'gc threadring' $O.out -n 50000000 } chameneos() { runonly echo 'chameneos 6000000' - run 'gcc -O2 chameneosredux.c -lpthread' a.out 6000000 + run "gcc $gccm -O2 chameneosredux.c -lpthread" a.out 6000000 run 'gccgo -O2 chameneosredux.go' a.out 6000000 run 'gc chameneosredux' $O.out 6000000 } diff --git a/test/bigalg.go b/test/bigalg.go index 55a15c30a..60e822942 100644 --- a/test/bigalg.go +++ b/test/bigalg.go @@ -15,18 +15,21 @@ type T struct { d byte } -var a = []int{ 1, 2, 3 } +var a = []int{1, 2, 3} var NIL []int func arraycmptest() { if NIL != nil { println("fail1:", NIL, "!= nil") + panic("bigalg") } if nil != NIL { println("fail2: nil !=", NIL) + panic("bigalg") } if a == nil || nil == a { println("fail3:", a, "== nil") + panic("bigalg") } } @@ -49,12 +52,14 @@ func maptest() { t1 := mt[0] if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { println("fail: map val struct", t1.a, t1.b, t1.c, t1.d) + panic("bigalg") } ma[1] = a a1 := ma[1] if !SameArray(a, a1) { println("fail: map val array", a, a1) + panic("bigalg") } } @@ -72,15 +77,18 @@ func chantest() { t1 := <-ct if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { println("fail: map val struct", t1.a, t1.b, t1.c, t1.d) + panic("bigalg") } a1 := <-ca if !SameArray(a, a1) { println("fail: map val array", a, a1) + panic("bigalg") } } -type E struct { } +type E struct{} + var e E func interfacetest() { @@ -90,6 +98,7 @@ func interfacetest() { a1 := i.([]int) if !SameArray(a, a1) { println("interface <-> []int", a, a1) + panic("bigalg") } pa := new([]int) *pa = a @@ -97,12 +106,14 @@ func interfacetest() { a1 = *i.(*[]int) if !SameArray(a, a1) { println("interface <-> *[]int", a, a1) + panic("bigalg") } i = t t1 := i.(T) if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { println("interface <-> struct", t1.a, t1.b, t1.c, t1.d) + panic("bigalg") } i = e diff --git a/test/blank.go b/test/blank.go index 961ed153b..7f7d9f6f7 100644 --- a/test/blank.go +++ b/test/blank.go @@ -8,6 +8,11 @@ package main +import ( + "os" + "unsafe" +) + import _ "fmt" var call string @@ -102,8 +107,19 @@ func main() { panic(sum) } + // exp/ssa/interp doesn't yet skip blank fields in struct + // equivalence. It also cannot support unsafe.Pointer. + if os.Getenv("GOSSAINTERP") == "" { + type T1 struct{ x, y, z int } + t1 := *(*T)(unsafe.Pointer(&T1{1, 2, 3})) + t2 := *(*T)(unsafe.Pointer(&T1{4, 5, 6})) + if t1 != t2 { + panic("T{} != T{}") + } + } + h(a, b) - + m() } @@ -113,7 +129,7 @@ type I interface { type TI struct{} -func (TI) M(x int, y int) { +func (_ TI) M(x int, y int) { if x != y { println("invalid M call:", x, y) panic("bad M") @@ -133,14 +149,13 @@ func fp1(x, y int) { } } - func m() { var i I - + i = TI{} i.M(1, 1) i.M(2, 2) - + fp(1, 1) fp(2, 2) } @@ -162,4 +177,3 @@ func _() { func ff() { var _ int = 1 } - diff --git a/test/blank1.go b/test/blank1.go index c6e038a0d..4edb2db70 100644 --- a/test/blank1.go +++ b/test/blank1.go @@ -9,8 +9,13 @@ package _ // ERROR "invalid package name _" +var t struct { + _ int +} + func main() { _() // ERROR "cannot use _ as value" x := _+1 // ERROR "cannot use _ as value" _ = x + _ = t._ // ERROR "cannot refer to blank field" } diff --git a/test/bom.go b/test/bom.go new file mode 100644 index 000000000..37f73bc5d --- /dev/null +++ b/test/bom.go @@ -0,0 +1,26 @@ +// runoutput + +// 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 source file beginning with a byte order mark. + +package main + +import ( + "fmt" + "strings" +) + +func main() { + prog = strings.Replace(prog, "BOM", "\uFEFF", -1) + fmt.Print(prog) +} + +var prog = `BOM +package main + +func main() { +} +` diff --git a/test/bombad.go b/test/bombad.go new file mode 100644 index 000000000..b894d9ba9 --- /dev/null +++ b/test/bombad.go @@ -0,0 +1,18 @@ +// 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. + +// Here for reference, but hard to test automatically +// because the BOM muddles the +// processing done by ../run. + +package main + +func main() { + // There's a bom here. // ERROR "BOM" + // And here. // ERROR "BOM" + /* And here.*/ // ERROR "BOM" + println("hi there") // and here // ERROR "BOM" +} diff --git a/test/bounds.go b/test/bounds.go new file mode 100644 index 000000000..50f7ad741 --- /dev/null +++ b/test/bounds.go @@ -0,0 +1,270 @@ +// errorcheck -0 -m -l + +// 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, using compiler diagnostic flags, that bounds check elimination +// is eliminating the correct checks. + +package foo + +var ( + s []int + + a1 [1]int + a1k [1000]int + a100k [100000]int + + p1 *[1]int + p1k *[1000]int + p100k *[100000]int + + i int + ui uint + i8 int8 + ui8 uint8 + i16 int16 + ui16 uint16 + i32 int32 + ui32 uint32 + i64 int64 + ui64 uint64 +) + +func main() { + // Most things need checks. + use(s[i]) + use(a1[i]) + use(a1k[i]) + use(a100k[i]) + use(p1[i]) + use(p1k[i]) + use(p100k[i]) + + use(s[ui]) + use(a1[ui]) + use(a1k[ui]) + use(a100k[ui]) + use(p1[ui]) + use(p1k[ui]) + use(p100k[ui]) + + use(s[i8]) + use(a1[i8]) + use(a1k[i8]) + use(a100k[i8]) + use(p1[i8]) + use(p1k[i8]) + use(p100k[i8]) + + // Unsigned 8-bit numbers don't need checks for len >= 2⁸. + use(s[ui8]) + use(a1[ui8]) + use(a1k[ui8]) // ERROR "index bounds check elided" + use(a100k[ui8]) // ERROR "index bounds check elided" + use(p1[ui8]) + use(p1k[ui8]) // ERROR "index bounds check elided" + use(p100k[ui8]) // ERROR "index bounds check elided" + + use(s[i16]) + use(a1[i16]) + use(a1k[i16]) + use(a100k[i16]) + use(p1[i16]) + use(p1k[i16]) + use(p100k[i16]) + + // Unsigned 16-bit numbers don't need checks for len >= 2¹⁶. + use(s[ui16]) + use(a1[ui16]) + use(a1k[ui16]) + use(a100k[ui16]) // ERROR "index bounds check elided" + use(p1[ui16]) + use(p1k[ui16]) + use(p100k[ui16]) // ERROR "index bounds check elided" + + use(s[i32]) + use(a1[i32]) + use(a1k[i32]) + use(a100k[i32]) + use(p1[i32]) + use(p1k[i32]) + use(p100k[i32]) + + use(s[ui32]) + use(a1[ui32]) + use(a1k[ui32]) + use(a100k[ui32]) + use(p1[ui32]) + use(p1k[ui32]) + use(p100k[ui32]) + + use(s[i64]) + use(a1[i64]) + use(a1k[i64]) + use(a100k[i64]) + use(p1[i64]) + use(p1k[i64]) + use(p100k[i64]) + + use(s[ui64]) + use(a1[ui64]) + use(a1k[ui64]) + use(a100k[ui64]) + use(p1[ui64]) + use(p1k[ui64]) + use(p100k[ui64]) + + // Mod truncates the maximum value to one less than the argument, + // but signed mod can be negative, so only unsigned mod counts. + use(s[i%999]) + use(a1[i%999]) + use(a1k[i%999]) + use(a100k[i%999]) + use(p1[i%999]) + use(p1k[i%999]) + use(p100k[i%999]) + + use(s[ui%999]) + use(a1[ui%999]) + use(a1k[ui%999]) // ERROR "index bounds check elided" + use(a100k[ui%999]) // ERROR "index bounds check elided" + use(p1[ui%999]) + use(p1k[ui%999]) // ERROR "index bounds check elided" + use(p100k[ui%999]) // ERROR "index bounds check elided" + + use(s[i%1000]) + use(a1[i%1000]) + use(a1k[i%1000]) + use(a100k[i%1000]) + use(p1[i%1000]) + use(p1k[i%1000]) + use(p100k[i%1000]) + + use(s[ui%1000]) + use(a1[ui%1000]) + use(a1k[ui%1000]) // ERROR "index bounds check elided" + use(a100k[ui%1000]) // ERROR "index bounds check elided" + use(p1[ui%1000]) + use(p1k[ui%1000]) // ERROR "index bounds check elided" + use(p100k[ui%1000]) // ERROR "index bounds check elided" + + use(s[i%1001]) + use(a1[i%1001]) + use(a1k[i%1001]) + use(a100k[i%1001]) + use(p1[i%1001]) + use(p1k[i%1001]) + use(p100k[i%1001]) + + use(s[ui%1001]) + use(a1[ui%1001]) + use(a1k[ui%1001]) + use(a100k[ui%1001]) // ERROR "index bounds check elided" + use(p1[ui%1001]) + use(p1k[ui%1001]) + use(p100k[ui%1001]) // ERROR "index bounds check elided" + + // Bitwise and truncates the maximum value to the mask value. + // The result (for a positive mask) cannot be negative, so elision + // applies to both signed and unsigned indexes. + use(s[i&999]) + use(a1[i&999]) + use(a1k[i&999]) // ERROR "index bounds check elided" + use(a100k[i&999]) // ERROR "index bounds check elided" + use(p1[i&999]) + use(p1k[i&999]) // ERROR "index bounds check elided" + use(p100k[i&999]) // ERROR "index bounds check elided" + + use(s[ui&999]) + use(a1[ui&999]) + use(a1k[ui&999]) // ERROR "index bounds check elided" + use(a100k[ui&999]) // ERROR "index bounds check elided" + use(p1[ui&999]) + use(p1k[ui&999]) // ERROR "index bounds check elided" + use(p100k[ui&999]) // ERROR "index bounds check elided" + + use(s[i&1000]) + use(a1[i&1000]) + use(a1k[i&1000]) + use(a100k[i&1000]) // ERROR "index bounds check elided" + use(p1[i&1000]) + use(p1k[i&1000]) + use(p100k[i&1000]) // ERROR "index bounds check elided" + + use(s[ui&1000]) + use(a1[ui&1000]) + use(a1k[ui&1000]) + use(a100k[ui&1000]) // ERROR "index bounds check elided" + use(p1[ui&1000]) + use(p1k[ui&1000]) + use(p100k[ui&1000]) // ERROR "index bounds check elided" + + // Right shift cuts the effective number of bits in the index, + // but only for unsigned (signed stays negative). + use(s[i32>>22]) + use(a1[i32>>22]) + use(a1k[i32>>22]) + use(a100k[i32>>22]) + use(p1[i32>>22]) + use(p1k[i32>>22]) + use(p100k[i32>>22]) + + use(s[ui32>>22]) + use(a1[ui32>>22]) + use(a1k[ui32>>22]) + use(a100k[ui32>>22]) // ERROR "index bounds check elided" + use(p1[ui32>>22]) + use(p1k[ui32>>22]) + use(p100k[ui32>>22]) // ERROR "index bounds check elided" + + use(s[i32>>23]) + use(a1[i32>>23]) + use(a1k[i32>>23]) + use(a100k[i32>>23]) + use(p1[i32>>23]) + use(p1k[i32>>23]) + use(p100k[i32>>23]) + + use(s[ui32>>23]) + use(a1[ui32>>23]) + use(a1k[ui32>>23]) // ERROR "index bounds check elided" + use(a100k[ui32>>23]) // ERROR "index bounds check elided" + use(p1[ui32>>23]) + use(p1k[ui32>>23]) // ERROR "index bounds check elided" + use(p100k[ui32>>23]) // ERROR "index bounds check elided" + + // Division cuts the range like right shift does. + use(s[i/1e6]) + use(a1[i/1e6]) + use(a1k[i/1e6]) + use(a100k[i/1e6]) + use(p1[i/1e6]) + use(p1k[i/1e6]) + use(p100k[i/1e6]) + + use(s[ui/1e6]) + use(a1[ui/1e6]) + use(a1k[ui/1e6]) + use(p1[ui/1e6]) + use(p1k[ui/1e6]) + + use(s[i/1e7]) + use(a1[i/1e7]) + use(a1k[i/1e7]) + use(a100k[i/1e7]) + use(p1[i/1e7]) + use(p1k[i/1e7]) + use(p100k[i/1e7]) + + use(s[ui/1e7]) + use(a1[ui/1e7]) + use(p1[ui/1e7]) +} + +var sum int + +func use(x int) { + sum += x +} diff --git a/test/bugs/bug395.go b/test/bugs/bug395.go index adf74497c..4632dcd0f 100644 --- a/test/bugs/bug395.go +++ b/test/bugs/bug395.go @@ -1,6 +1,9 @@ // echo bug395 is broken # takes 90+ seconds to break // # $G $D/$F.go || echo bug395 +// 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/chan/select5.go b/test/chan/select5.go index 13cde1afe..f72cfe4b4 100644 --- a/test/chan/select5.go +++ b/test/chan/select5.go @@ -1,6 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && -// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: select5 -// rm -f tmp.go +// runoutput // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/closure.go b/test/closure.go index ae38900ba..c4a312464 100644 --- a/test/closure.go +++ b/test/closure.go @@ -81,6 +81,7 @@ func h() { func newfunc() func(int) int { return func(x int) int { return x } } func main() { + runtime.GOMAXPROCS(1) var fail bool go f() diff --git a/test/cmp.go b/test/cmp.go index a56ca6ead..5be64561d 100644 --- a/test/cmp.go +++ b/test/cmp.go @@ -8,9 +8,13 @@ package main -import "unsafe" +import ( + "os" + "unsafe" +) var global bool + func use(b bool) { global = b } func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) } @@ -38,8 +42,12 @@ func main() { var c string = "hello" var d string = "hel" // try to get different pointer d = d + "lo" - if stringptr(c) == stringptr(d) { - panic("compiler too smart -- got same string") + + // exp/ssa/interp can't handle unsafe.Pointer. + if os.Getenv("GOSSAINTERP") != "" { + if stringptr(c) == stringptr(d) { + panic("compiler too smart -- got same string") + } } var e = make(chan int) @@ -283,7 +291,7 @@ func main() { isfalse(ix != z) isfalse(iz != x) } - + // structs with _ fields { var x = struct { @@ -296,7 +304,7 @@ func main() { x: 1, y: 2, z: 3, } var ix interface{} = x - + istrue(x == x) istrue(x == ix) istrue(ix == x) diff --git a/test/cmplxdivide.go b/test/cmplxdivide.go index 92a98356d..40c84486d 100644 --- a/test/cmplxdivide.go +++ b/test/cmplxdivide.go @@ -45,4 +45,7 @@ func main() { fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x) } } + if bad { + panic("cmplxdivide failed.") + } } diff --git a/test/const.go b/test/const.go index 80fbfaf3e..d583659c6 100644 --- a/test/const.go +++ b/test/const.go @@ -8,27 +8,29 @@ package main +import "os" + const ( - c0 = 0 - cm1 = -1 - chuge = 1 << 100 + c0 = 0 + cm1 = -1 + chuge = 1 << 100 chuge_1 = chuge - 1 - c1 = chuge >> 100 - c3div2 = 3/2 - c1e3 = 1e3 + c1 = chuge >> 100 + c3div2 = 3 / 2 + c1e3 = 1e3 - ctrue = true + ctrue = true cfalse = !ctrue ) const ( - f0 = 0.0 - fm1 = -1. - fhuge float64 = 1 << 100 + f0 = 0.0 + fm1 = -1. + fhuge float64 = 1 << 100 fhuge_1 float64 = chuge - 1 - f1 float64 = chuge >> 100 - f3div2 = 3./2. - f1e3 float64 = 1e3 + f1 float64 = chuge >> 100 + f3div2 = 3. / 2. + f1e3 float64 = 1e3 ) func assert(t bool, s string) { @@ -41,8 +43,8 @@ func ints() { assert(c0 == 0, "c0") assert(c1 == 1, "c1") assert(chuge > chuge_1, "chuge") - assert(chuge_1 + 1 == chuge, "chuge 1") - assert(chuge + cm1 +1 == chuge, "cm1") + assert(chuge_1+1 == chuge, "chuge 1") + assert(chuge+cm1+1 == chuge, "cm1") assert(c3div2 == 1, "3/2") assert(c1e3 == 1000, "c1e3 int") assert(c1e3 == 1e3, "c1e3 float") @@ -81,9 +83,12 @@ func ints() { func floats() { assert(f0 == c0, "f0") assert(f1 == c1, "f1") - assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1. - assert(fhuge_1 + 1 == fhuge, "fhuge 1") - assert(fhuge + fm1 +1 == fhuge, "fm1") + // TODO(gri): exp/ssa/interp constant folding is incorrect. + if os.Getenv("GOSSAINTERP") == "" { + assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1. + } + assert(fhuge_1+1 == fhuge, "fhuge 1") + assert(fhuge+fm1+1 == fhuge, "fm1") assert(f3div2 == 1.5, "3./2.") assert(f1e3 == 1000, "f1e3 int") assert(f1e3 == 1.e3, "f1e3 float") diff --git a/test/const1.go b/test/const1.go index bc399c01c..a170ce9e7 100644 --- a/test/const1.go +++ b/test/const1.go @@ -9,6 +9,8 @@ package main +import "unsafe" + type I interface{} const ( @@ -66,7 +68,7 @@ var ( c3 float64 = float64(Big) * Big // ERROR "overflow" c4 = Big * Big // ERROR "overflow" c5 = Big / 0 // ERROR "division by zero" - c6 = 1000 % 1e3 // ERROR "floating-point % operation" + c6 = 1000 % 1e3 // ERROR "floating-point % operation|expected integer type" ) func f(int) @@ -86,3 +88,7 @@ func main() { } const ptr = nil // ERROR "const.*nil" +const _ = string([]byte(nil)) // ERROR "is not a constant" +const _ = uintptr(unsafe.Pointer((*int)(nil))) // ERROR "is not a constant" +const _ = unsafe.Pointer((*int)(nil)) // ERROR "cannot be nil" +const _ = (*int)(nil) // ERROR "cannot be nil" diff --git a/test/const2.go b/test/const2.go index 97d3d4c7d..048d0cb9f 100644 --- a/test/const2.go +++ b/test/const2.go @@ -16,6 +16,6 @@ const ( const LargeA = 1000000000000000000 const LargeB = LargeA * LargeA * LargeA -const LargeC = LargeB * LargeB * LargeB // ERROR "constant multiplication overflow" +const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow" -const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // ERROR "constant shift overflow" +const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow" diff --git a/test/const4.go b/test/const4.go index 677fcefa7..2fb2d0664 100644 --- a/test/const4.go +++ b/test/const4.go @@ -9,7 +9,7 @@ package main var b struct { - a[10]int + a [10]int } var m map[string][20]int @@ -61,17 +61,22 @@ var c1 = func() chan *[70]int { func main() { if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 { println("BUG:", n1, n2, n3, n4, n5, n6, n7) + panic("fail") } if !calledF { println("BUG: did not call f") + panic("fail") } if <-c == nil { println("BUG: did not receive from c") + panic("fail") } if !calledG { println("BUG: did not call g") + panic("fail") } if <-c1 == nil { println("BUG: did not receive from c1") + panic("fail") } } diff --git a/test/const5.go b/test/const5.go index 8e0385e9a..87fe33a38 100644 --- a/test/const5.go +++ b/test/const5.go @@ -24,10 +24,10 @@ const ( n2 = len(m[""]) n3 = len(s[10]) - n4 = len(f()) // ERROR "must be constant" - n5 = len(<-c) // ERROR "must be constant" + n4 = len(f()) // ERROR "is not a constant|is not constant" + n5 = len(<-c) // ERROR "is not a constant|is not constant" - n6 = cap(f()) // ERROR "must be constant" - n7 = cap(<-c) // ERROR "must be constant" + n6 = cap(f()) // ERROR "is not a constant|is not constant" + n7 = cap(<-c) // ERROR "is not a constant|is not constant" ) diff --git a/test/const6.go b/test/const6.go new file mode 100644 index 000000000..c04435db6 --- /dev/null +++ b/test/const6.go @@ -0,0 +1,30 @@ +// 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. + +// Ideal vs non-ideal bool. See issue 3915, 3923. + +package p + +type mybool bool +type mybool1 bool + +var ( + x, y int = 1, 2 + c1 bool = x < y + c2 mybool = x < y + c3 mybool = c2 == (x < y) + c4 mybool = c2 == (1 < 2) + c5 mybool = 1 < 2 + c6 mybool1 = x < y + c7 = c1 == c2 // ERROR "mismatched types" + c8 = c2 == c6 // ERROR "mismatched types" + c9 = c1 == c6 // ERROR "mismatched types" + _ = c2 && (x < y) + _ = c2 && (1 < 2) + _ = c1 && c2 // ERROR "mismatched types" + _ = c2 && c6 // ERROR "mismatched types" + _ = c1 && c6 // ERROR "mismatched types" +) diff --git a/test/convT2X.go b/test/convT2X.go new file mode 100644 index 000000000..7e27f06b0 --- /dev/null +++ b/test/convT2X.go @@ -0,0 +1,195 @@ +// 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 conversion from non-interface types to the empty interface. + +package main + +type J interface { + Method() +} + +type ( + U16 uint16 + U32 uint32 + U64 uint64 + U128 [2]uint64 + F32 float32 + F64 float64 + C128 complex128 + S string + B []byte + M map[int]int + C chan int + Z struct{} +) + +func (U16) Method() {} +func (U32) Method() {} +func (U64) Method() {} +func (U128) Method() {} +func (F32) Method() {} +func (F64) Method() {} +func (C128) Method() {} +func (S) Method() {} +func (B) Method() {} +func (M) Method() {} +func (C) Method() {} +func (Z) Method() {} + +var ( + u16 = U16(1) + u32 = U32(2) + u64 = U64(3) + u128 = U128{4, 5} + f32 = F32(6) + f64 = F64(7) + c128 = C128(8 + 9i) + s = S("10") + b = B("11") + m = M{12: 13} + c = make(C, 14) + z = Z{} + p = &z + pp = &p +) + +var ( + iu16 interface{} = u16 + iu32 interface{} = u32 + iu64 interface{} = u64 + iu128 interface{} = u128 + if32 interface{} = f32 + if64 interface{} = f64 + ic128 interface{} = c128 + is interface{} = s + ib interface{} = b + im interface{} = m + ic interface{} = c + iz interface{} = z + ip interface{} = p + ipp interface{} = pp + + ju16 J = u16 + ju32 J = u32 + ju64 J = u64 + ju128 J = u128 + jf32 J = f32 + jf64 J = f64 + jc128 J = c128 + js J = s + jb J = b + jm J = m + jc J = c + jz J = z + jp J = p // The method set for *T contains the methods for T. + // pp does not implement error. +) + +func second(a ...interface{}) interface{} { + return a[1] +} + +func main() { + // Test equality. + if u16 != iu16 { + panic("u16 != iu16") + } + if u16 != ju16 { + panic("u16 != ju16") + } + if u32 != iu32 { + panic("u32 != iu32") + } + if u32 != ju32 { + panic("u32 != ju32") + } + if u64 != iu64 { + panic("u64 != iu64") + } + if u64 != ju64 { + panic("u64 != ju64") + } + if u128 != iu128 { + panic("u128 != iu128") + } + if u128 != ju128 { + panic("u128 != ju128") + } + if f32 != if32 { + panic("f32 != if32") + } + if f32 != jf32 { + panic("f32 != jf32") + } + if f64 != if64 { + panic("f64 != if64") + } + if f64 != jf64 { + panic("f64 != jf64") + } + if c128 != ic128 { + panic("c128 != ic128") + } + if c128 != jc128 { + panic("c128 != jc128") + } + if s != is { + panic("s != is") + } + if s != js { + panic("s != js") + } + if c != ic { + panic("c != ic") + } + if c != jc { + panic("c != jc") + } + // There are no tests for b and m, as slices and maps are not comparable by ==. + if z != iz { + panic("z != iz") + } + if z != jz { + panic("z != jz") + } + if p != ip { + panic("p != ip") + } + if p != jp { + panic("p != jp") + } + if pp != ipp { + panic("pp != ipp") + } + // pp does not implement J. + + // Test that non-interface types can be used as ...interface{} arguments. + if got := second(z, p, pp, u16, u32, u64, u128, f32, f64, c128, s, b, m, c); got != ip { + println("second: got", got, "want", ip) + panic("fail") + } + + // Test that non-interface types can be sent on a chan interface{}. + const n = 100 + uc := make(chan interface{}) + go func() { + for i := 0; i < n; i++ { + select { + case uc <- nil: + case uc <- u32: + case uc <- u64: + case uc <- u128: + } + } + }() + for i := 0; i < n; i++ { + if got := <-uc; got != nil && got != u32 && got != u64 && got != u128 { + println("recv: i", i, "got", got) + panic("fail") + } + } +} diff --git a/test/copy.go b/test/copy.go index 65ffb6ff8..e6108d905 100644 --- a/test/copy.go +++ b/test/copy.go @@ -132,6 +132,7 @@ func verify8(length, in, out, m int) { n := ncopied(length, in, out) if m != n { fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) + os.Exit(1) return } // before @@ -172,6 +173,7 @@ func verifyS(length, in, out, m int) { n := ncopied(length, in, out) if m != n { fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) + os.Exit(1) return } // before @@ -212,6 +214,7 @@ func verify16(length, in, out, m int) { n := ncopied(length, in, out) if m != n { fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) + os.Exit(1) return } // before @@ -252,6 +255,7 @@ func verify32(length, in, out, m int) { n := ncopied(length, in, out) if m != n { fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) + os.Exit(1) return } // before @@ -292,6 +296,7 @@ func verify64(length, in, out, m int) { n := ncopied(length, in, out) if m != n { fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) + os.Exit(1) return } // before diff --git a/test/crlf.go b/test/crlf.go index 292b63bf4..2d56889b0 100644 --- a/test/crlf.go +++ b/test/crlf.go @@ -1,6 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && -// $G tmp.go && $L tmp.$A && ./$A.out -// rm -f tmp.go +// runoutput // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/ddd1.go b/test/ddd1.go index 1e070093c..07981af12 100644 --- a/test/ddd1.go +++ b/test/ddd1.go @@ -22,6 +22,16 @@ var ( _ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible" ) +func sum3(int, int, int) int { return 0 } +func tuple() (int, int, int) { return 1, 2, 3 } + +var ( + _ = sum(tuple()) + _ = sum(tuple()...) // ERROR "multiple-value|[.][.][.]" + _ = sum3(tuple()) + _ = sum3(tuple()...) // ERROR "multiple-value|[.][.][.]" "not enough" +) + type T []T func funny(args ...T) int { return 0 } diff --git a/test/ddd2.dir/ddd2.go b/test/ddd2.dir/ddd2.go new file mode 100644 index 000000000..c9a267592 --- /dev/null +++ b/test/ddd2.dir/ddd2.go @@ -0,0 +1,16 @@ +// 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. + +// This file is compiled and then imported by ddd3.go. + +package ddd + +func Sum(args ...int) int { + s := 0 + for _, v := range args { + s += v + } + return s +} + diff --git a/test/ddd3.go b/test/ddd2.dir/ddd3.go index 82fce3149..5486fe8a0 100644 --- a/test/ddd3.go +++ b/test/ddd2.dir/ddd3.go @@ -1,5 +1,3 @@ -// $G $D/ddd2.go && $G $D/$F.go && $L $F.$A && ./$A.out - // 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/ddd2.go b/test/ddd2.go index a141a39c7..0d9f634ab 100644 --- a/test/ddd2.go +++ b/test/ddd2.go @@ -1,18 +1,9 @@ -// skip +// rundir // 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. -// This file is compiled and then imported by ddd3.go. - -package ddd - -func Sum(args ...int) int { - s := 0 - for _, v := range args { - s += v - } - return s -} +// Test that variadic functions work across package boundaries. +package ignored diff --git a/test/decl.go b/test/decl.go index 6f84245f1..e2f126adb 100644 --- a/test/decl.go +++ b/test/decl.go @@ -33,8 +33,9 @@ func main() { m, h, s := f3() _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h } - if x() != "3" { - println("x() failed") + if y := x(); y != "3" { + println("x() failed", y) + panic("fail") } _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h } diff --git a/test/declbad.go b/test/declbad.go index 32d68e7ea..728eceb7f 100644 --- a/test/declbad.go +++ b/test/declbad.go @@ -39,6 +39,14 @@ func main() { _, _, _ = i, f, s } { + // multiline no new variables + i := f1 + i := func() int { // ERROR "redeclared|no new|incompatible" + return 0 + } + _ = i + } + { // single redeclaration i, f, s := f3() i := 1 // ERROR "redeclared|no new|incompatible" diff --git a/test/defer.go b/test/defer.go index 2f67d3560..6731ab7ee 100644 --- a/test/defer.go +++ b/test/defer.go @@ -25,6 +25,7 @@ func test1() { test1helper() if result != "9876543210" { fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result) + panic("defer") } } @@ -41,6 +42,7 @@ func test2() { test2helper() if result != "9876543210" { fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result) + panic("defer") } } diff --git a/test/divide.go b/test/divide.go index c91a33e9d..b20f1062f 100644 --- a/test/divide.go +++ b/test/divide.go @@ -13,36 +13,44 @@ import "fmt" func f8(x, y, q, r int8) { if t := x / y; t != q { fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) + panic("divide") } if t := x % y; t != r { fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) + panic("divide") } } func f16(x, y, q, r int16) { if t := x / y; t != q { fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) + panic("divide") } if t := x % y; t != r { fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) + panic("divide") } } func f32(x, y, q, r int32) { if t := x / y; t != q { fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) + panic("divide") } if t := x % y; t != r { fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) + panic("divide") } } func f64(x, y, q, r int64) { if t := x / y; t != q { fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) + panic("divide") } if t := x % y; t != r { fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) + panic("divide") } } diff --git a/test/dwarf/main.go b/test/dwarf/dwarf.dir/main.go index 7f2ec4c00..175a09c77 100644 --- a/test/dwarf/main.go +++ b/test/dwarf/dwarf.dir/main.go @@ -1,5 +1,8 @@ // $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out +// 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/dwarf/z1.go b/test/dwarf/dwarf.dir/z1.go index 7f163e9a1..7f163e9a1 100644 --- a/test/dwarf/z1.go +++ b/test/dwarf/dwarf.dir/z1.go diff --git a/test/dwarf/z10.go b/test/dwarf/dwarf.dir/z10.go index 19c70020e..19c70020e 100644 --- a/test/dwarf/z10.go +++ b/test/dwarf/dwarf.dir/z10.go diff --git a/test/dwarf/z11.go b/test/dwarf/dwarf.dir/z11.go index c1d2f9180..c1d2f9180 100644 --- a/test/dwarf/z11.go +++ b/test/dwarf/dwarf.dir/z11.go diff --git a/test/dwarf/z12.go b/test/dwarf/dwarf.dir/z12.go index 7455f1894..7455f1894 100644 --- a/test/dwarf/z12.go +++ b/test/dwarf/dwarf.dir/z12.go diff --git a/test/dwarf/z13.go b/test/dwarf/dwarf.dir/z13.go index ecb3c4c8c..ecb3c4c8c 100644 --- a/test/dwarf/z13.go +++ b/test/dwarf/dwarf.dir/z13.go diff --git a/test/dwarf/z14.go b/test/dwarf/dwarf.dir/z14.go index 134b39b64..134b39b64 100644 --- a/test/dwarf/z14.go +++ b/test/dwarf/dwarf.dir/z14.go diff --git a/test/dwarf/z15.go b/test/dwarf/dwarf.dir/z15.go index d73819b44..d73819b44 100644 --- a/test/dwarf/z15.go +++ b/test/dwarf/dwarf.dir/z15.go diff --git a/test/dwarf/z16.go b/test/dwarf/dwarf.dir/z16.go index 6c31651ba..6c31651ba 100644 --- a/test/dwarf/z16.go +++ b/test/dwarf/dwarf.dir/z16.go diff --git a/test/dwarf/z17.go b/test/dwarf/dwarf.dir/z17.go index b742d1672..b742d1672 100644 --- a/test/dwarf/z17.go +++ b/test/dwarf/dwarf.dir/z17.go diff --git a/test/dwarf/z18.go b/test/dwarf/dwarf.dir/z18.go index 84150ff0a..84150ff0a 100644 --- a/test/dwarf/z18.go +++ b/test/dwarf/dwarf.dir/z18.go diff --git a/test/dwarf/z19.go b/test/dwarf/dwarf.dir/z19.go index bb2e29684..bb2e29684 100644 --- a/test/dwarf/z19.go +++ b/test/dwarf/dwarf.dir/z19.go diff --git a/test/dwarf/z2.go b/test/dwarf/dwarf.dir/z2.go index 68bd58257..68bd58257 100644 --- a/test/dwarf/z2.go +++ b/test/dwarf/dwarf.dir/z2.go diff --git a/test/dwarf/z20.go b/test/dwarf/dwarf.dir/z20.go index 03111e184..03111e184 100644 --- a/test/dwarf/z20.go +++ b/test/dwarf/dwarf.dir/z20.go diff --git a/test/dwarf/z3.go b/test/dwarf/dwarf.dir/z3.go index 5e4ad3ae2..5e4ad3ae2 100644 --- a/test/dwarf/z3.go +++ b/test/dwarf/dwarf.dir/z3.go diff --git a/test/dwarf/z4.go b/test/dwarf/dwarf.dir/z4.go index 1f28465c5..1f28465c5 100644 --- a/test/dwarf/z4.go +++ b/test/dwarf/dwarf.dir/z4.go diff --git a/test/dwarf/z5.go b/test/dwarf/dwarf.dir/z5.go index 7f4eeb419..7f4eeb419 100644 --- a/test/dwarf/z5.go +++ b/test/dwarf/dwarf.dir/z5.go diff --git a/test/dwarf/z6.go b/test/dwarf/dwarf.dir/z6.go index 241791dff..241791dff 100644 --- a/test/dwarf/z6.go +++ b/test/dwarf/dwarf.dir/z6.go diff --git a/test/dwarf/z7.go b/test/dwarf/dwarf.dir/z7.go index 68c1ad0c2..68c1ad0c2 100644 --- a/test/dwarf/z7.go +++ b/test/dwarf/dwarf.dir/z7.go diff --git a/test/dwarf/z8.go b/test/dwarf/dwarf.dir/z8.go index 16eed32a2..16eed32a2 100644 --- a/test/dwarf/z8.go +++ b/test/dwarf/dwarf.dir/z8.go diff --git a/test/dwarf/z9.go b/test/dwarf/dwarf.dir/z9.go index cbb94b4d2..cbb94b4d2 100644 --- a/test/dwarf/z9.go +++ b/test/dwarf/dwarf.dir/z9.go diff --git a/test/dwarf/dwarf.go b/test/dwarf/dwarf.go new file mode 100644 index 000000000..32dd7d3d5 --- /dev/null +++ b/test/dwarf/dwarf.go @@ -0,0 +1,10 @@ +// 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. + +// See issue 2241 and issue 1878: dwarf include stack size +// issues in linker. + +package ignored diff --git a/test/escape.go b/test/escape.go index e487bb895..252a1e59c 100644 --- a/test/escape.go +++ b/test/escape.go @@ -18,15 +18,15 @@ var allptr = make([]*int, 0, 100) func noalias(p, q *int, s string) { n := len(allptr) - *p = -(n+1) - *q = -(n+2) - allptr = allptr[0:n+2] + *p = -(n + 1) + *q = -(n + 2) + allptr = allptr[0 : n+2] allptr[n] = p allptr[n+1] = q n += 2 for i := 0; i < n; i++ { if allptr[i] != nil && *allptr[i] != -(i+1) { - println("aliased pointers", -(i+1), *allptr[i], "after", s) + println("aliased pointers", -(i + 1), *allptr[i], "after", s) allptr[i] = nil bad = true } @@ -52,9 +52,11 @@ func chk(p, q *int, v int, s string) { func chkalias(p, q *int, v int, s string) { if p != q { println("want aliased pointers but got different after", s) + bad = true } if *q != v+1 { println("wrong value want", v+1, "got", *q, "after", s) + bad = true } } @@ -141,15 +143,27 @@ func for_escapes2(x int, y int) (*int, *int) { return p[0], p[1] } +func for_escapes3(x int, y int) (*int, *int) { + var f [2]func() *int + n := 0 + for i := x; n < 2; i = y { + p := new(int) + *p = i + f[n] = func() *int { return p } + n++ + } + return f[0](), f[1]() +} + func out_escapes(i int) (x int, p *int) { x = i - p = &x // ERROR "address of out parameter" + p = &x // ERROR "address of out parameter" return } func out_escapes_2(i int) (x int, p *int) { x = i - return x, &x // ERROR "address of out parameter" + return x, &x // ERROR "address of out parameter" } func defer1(i int) (x int) { @@ -187,6 +201,9 @@ func main() { p, q = for_escapes2(103, 104) chkalias(p, q, 103, "for_escapes2") + p, q = for_escapes3(105, 106) + chk(p, q, 105, "for_escapes3") + _, p = out_escapes(15) _, q = out_escapes(16) chk(p, q, 15, "out_escapes") diff --git a/test/escape2.go b/test/escape2.go index 0bf02c534..948161933 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -1,4 +1,4 @@ -// errchk -0 $G -m -l $D/$F.go +// errorcheck -0 -m -l // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -142,13 +142,13 @@ func (b Bar) AlsoLeak() *int { // ERROR "leaking param: b" } func (b Bar) LeaksToo() *int { // ERROR "leaking param: b" - v := 0 // ERROR "moved to heap: v" + v := 0 // ERROR "moved to heap: v" b.ii = &v // ERROR "&v escapes" return b.ii } func (b *Bar) LeaksABit() *int { // ERROR "b does not escape" - v := 0 // ERROR "moved to heap: v" + v := 0 // ERROR "moved to heap: v" b.ii = &v // ERROR "&v escapes" return b.ii } @@ -540,6 +540,19 @@ func foo74() { } } +// issue 3975 +func foo74b() { + var array [3]func() + s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape" + for i, v := range s { + vv := v // ERROR "moved to heap: vv" + // actually just escapes its scope + array[i] = func() { // ERROR "func literal escapes to heap" + println(vv) // ERROR "&vv escapes to heap" + } + } +} + func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y" return y } @@ -548,12 +561,21 @@ func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not esca return &x[0] // ERROR "&x.0. escapes to heap" } -func foo75(z *int) { // ERROR "leaking param: z" +func foo75(z *int) { // ERROR "z does not escape" myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" } func foo75a(z *int) { // ERROR "z does not escape" - myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" + myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" +} + +func foo75esc(z *int) { // ERROR "leaking param: z" + gxx = myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" +} + +func foo75aesc(z *int) { // ERROR "z does not escape" + var ppi **interface{} // assignments to pointer dereferences lose track + *ppi = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" } func foo76(z *int) { // ERROR "leaking param: z" @@ -561,7 +583,7 @@ func foo76(z *int) { // ERROR "leaking param: z" } func foo76a(z *int) { // ERROR "leaking param: z" - myprint1(nil, z) // ERROR "[.][.][.] argument escapes to heap" + myprint1(nil, z) // ERROR "[.][.][.] argument does not escape" } func foo76b() { @@ -569,7 +591,7 @@ func foo76b() { } func foo76c() { - myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" + myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" } func foo76d() { @@ -577,7 +599,7 @@ func foo76d() { } func foo76e() { - defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" + defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" } func foo76f() { @@ -597,10 +619,15 @@ func foo77(z []interface{}) { // ERROR "z does not escape" myprint(nil, z...) // z does not escape } -func foo77a(z []interface{}) { // ERROR "leaking param: z" +func foo77a(z []interface{}) { // ERROR "z does not escape" myprint1(nil, z...) } +func foo77b(z []interface{}) { // ERROR "leaking param: z" + var ppi **interface{} + *ppi = myprint1(nil, z...) +} + func foo78(z int) *int { // ERROR "moved to heap: z" return &z // ERROR "&z escapes to heap" } @@ -633,6 +660,21 @@ func foo81() *int { return nil } +func tee(p *int) (x, y *int) { return p, p } // ERROR "leaking param" + +func noop(x, y *int) {} // ERROR "does not escape" + +func foo82() { + var x, y, z int // ERROR "moved to heap" + go noop(tee(&z)) // ERROR "&z escapes to heap" + go noop(&x, &y) // ERROR "escapes to heap" + for { + var u, v, w int // ERROR "moved to heap" + defer noop(tee(&u)) // ERROR "&u escapes to heap" + defer noop(&v, &w) // ERROR "escapes to heap" + } +} + type Fooer interface { Foo() } @@ -1066,29 +1108,29 @@ L1: _ = i } -func foo124(x **int) { // ERROR "x does not escape" - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes" - func() { // ERROR "func literal does not escape" - *x = p // ERROR "leaking closure reference p" +func foo124(x **int) { // ERROR "x does not escape" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes" + func() { // ERROR "func literal does not escape" + *x = p // ERROR "leaking closure reference p" }() } -func foo125(ch chan *int) { // ERROR "does not escape" - var i int // ERROR "moved to heap" - p := &i // ERROR "&i escapes to heap" - func() { // ERROR "func literal does not escape" - ch <- p // ERROR "leaking closure reference p" +func foo125(ch chan *int) { // ERROR "does not escape" + var i int // ERROR "moved to heap" + p := &i // ERROR "&i escapes to heap" + func() { // ERROR "func literal does not escape" + ch <- p // ERROR "leaking closure reference p" }() } func foo126() { - var px *int // loopdepth 0 + var px *int // loopdepth 0 for { // loopdepth 1 - var i int // ERROR "moved to heap" + var i int // ERROR "moved to heap" func() { // ERROR "func literal does not escape" - px = &i // ERROR "&i escapes" + px = &i // ERROR "&i escapes" }() } } @@ -1096,8 +1138,8 @@ func foo126() { var px *int func foo127() { - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes to heap" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes to heap" q := p px = q } @@ -1110,12 +1152,12 @@ func foo128() { } func foo129() { - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes to heap" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes to heap" func() { // ERROR "func literal does not escape" - q := p // ERROR "leaking closure reference p" - func() { // ERROR "func literal does not escape" - r := q // ERROR "leaking closure reference q" + q := p // ERROR "leaking closure reference p" + func() { // ERROR "func literal does not escape" + r := q // ERROR "leaking closure reference q" px = r }() }() @@ -1123,40 +1165,40 @@ func foo129() { func foo130() { for { - var i int // ERROR "moved to heap" + var i int // ERROR "moved to heap" func() { // ERROR "func literal does not escape" - px = &i // ERROR "&i escapes" "leaking closure reference i" + px = &i // ERROR "&i escapes" "leaking closure reference i" }() } } func foo131() { - var i int // ERROR "moved to heap" + var i int // ERROR "moved to heap" func() { // ERROR "func literal does not escape" - px = &i // ERROR "&i escapes" "leaking closure reference i" + px = &i // ERROR "&i escapes" "leaking closure reference i" }() } func foo132() { - var i int // ERROR "moved to heap" - go func() { // ERROR "func literal escapes to heap" - px = &i // ERROR "&i escapes" "leaking closure reference i" + var i int // ERROR "moved to heap" + go func() { // ERROR "func literal escapes to heap" + px = &i // ERROR "&i escapes" "leaking closure reference i" }() } func foo133() { - var i int // ERROR "moved to heap" - defer func() { // ERROR "func literal does not escape" - px = &i // ERROR "&i escapes" "leaking closure reference i" + var i int // ERROR "moved to heap" + defer func() { // ERROR "func literal does not escape" + px = &i // ERROR "&i escapes" "leaking closure reference i" }() } func foo134() { var i int p := &i // ERROR "&i does not escape" - func() { // ERROR "func literal does not escape" + func() { // ERROR "func literal does not escape" q := p - func() { // ERROR "func literal does not escape" + func() { // ERROR "func literal does not escape" r := q _ = r }() @@ -1164,11 +1206,11 @@ func foo134() { } func foo135() { - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes to heap" "moved to heap: p" - go func() { // ERROR "func literal escapes to heap" - q := p // ERROR "&p escapes to heap" - func() { // ERROR "func literal does not escape" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes to heap" "moved to heap: p" + go func() { // ERROR "func literal escapes to heap" + q := p // ERROR "&p escapes to heap" + func() { // ERROR "func literal does not escape" r := q _ = r }() @@ -1176,11 +1218,11 @@ func foo135() { } func foo136() { - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes to heap" "moved to heap: p" - go func() { // ERROR "func literal escapes to heap" - q := p // ERROR "&p escapes to heap" "leaking closure reference p" - func() { // ERROR "func literal does not escape" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes to heap" "moved to heap: p" + go func() { // ERROR "func literal escapes to heap" + q := p // ERROR "&p escapes to heap" "leaking closure reference p" + func() { // ERROR "func literal does not escape" r := q // ERROR "leaking closure reference q" px = r }() @@ -1188,13 +1230,73 @@ func foo136() { } func foo137() { - var i int // ERROR "moved to heap: i" - p := &i // ERROR "&i escapes to heap" + var i int // ERROR "moved to heap: i" + p := &i // ERROR "&i escapes to heap" func() { // ERROR "func literal does not escape" - q := p // ERROR "leaking closure reference p" "moved to heap: q" + q := p // ERROR "leaking closure reference p" "moved to heap: q" go func() { // ERROR "func literal escapes to heap" - r := q // ERROR "&q escapes to heap" + r := q // ERROR "&q escapes to heap" _ = r }() }() } + +func foo138() *byte { + type T struct { + x [1]byte + } + t := new(T) // ERROR "new.T. escapes to heap" + return &t.x[0] // ERROR "&t.x.0. escapes to heap" +} + +func foo139() *byte { + type T struct { + x struct { + y byte + } + } + t := new(T) // ERROR "new.T. escapes to heap" + return &t.x.y // ERROR "&t.x.y escapes to heap" +} + +// issue 4751 +func foo140() interface{} { + type T struct { + X string + } + type U struct { + X string + T *T + } + t := &T{} // ERROR "&T literal escapes to heap" + return U{ + X: t.X, + T: t, + } +} + +//go:noescape + +func F1([]byte) + +func F2([]byte) + +//go:noescape + +func F3(x []byte) // ERROR "F3 x does not escape" + +func F4(x []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" + + var buf3 [10]byte + F3(buf3[:]) // ERROR "buf3 does not escape" + + var buf4 [10]byte // ERROR "moved to heap: buf4" + F4(buf4[:]) // ERROR "buf4 escapes to heap" +} diff --git a/test/escape4.go b/test/escape4.go index 887570896..83bc8eb12 100644 --- a/test/escape4.go +++ b/test/escape4.go @@ -1,4 +1,4 @@ -// errchk -0 $G -m $D/$F.go +// errorcheck -0 -m // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -37,3 +37,21 @@ func f2() {} // ERROR "can inline f2" // No inline for panic, recover. func f3() { panic(1) } func f4() { recover() } + +func f5() *byte { + type T struct { + x [1]byte + } + t := new(T) // ERROR "new.T. escapes to heap" + return &t.x[0] // ERROR "&t.x.0. escapes to heap" +} + +func f6() *byte { + type T struct { + x struct { + y byte + } + } + t := new(T) // ERROR "new.T. escapes to heap" + return &t.x.y // ERROR "&t.x.y escapes to heap" +} diff --git a/test/escape5.go b/test/escape5.go new file mode 100644 index 000000000..6b327fe9e --- /dev/null +++ b/test/escape5.go @@ -0,0 +1,144 @@ +// errorcheck -0 -m -l + +// 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, using compiler diagnostic flags, that the escape analysis is working. +// Compiles but does not run. Inlining is disabled. + +package foo + +func noleak(p *int) int { // ERROR "p does not escape" + return *p +} + +func leaktoret(p *int) *int { // ERROR "leaking param: p to result" + return p +} + +func leaktoret2(p *int) (*int, *int) { // ERROR "leaking param: p to result .anon1" "leaking param: p to result .anon2" + return p, p +} + +func leaktoret22(p, q *int) (*int, *int) { // ERROR "leaking param: p to result .anon2" "leaking param: q to result .anon3" + return p, q +} + +func leaktoret22b(p, q *int) (*int, *int) { // ERROR "leaking param: p to result .anon3" "leaking param: q to result .anon2" + return leaktoret22(q, p) +} + +func leaktoret22c(p, q *int) (*int, *int) { // ERROR "leaking param: p to result .anon3" "leaking param: q to result .anon2" + r, s := leaktoret22(q, p) + return r, s +} + +func leaktoret22d(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r" + r, s = leaktoret22(q, p) + return +} + +func leaktoret22e(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r" + r, s = leaktoret22(q, p) + return r, s +} + +func leaktoret22f(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r" + rr, ss := leaktoret22(q, p) + return rr, ss +} + +var gp *int + +func leaktosink(p *int) *int { // ERROR "leaking param: p" + gp = p + return p +} + +func f1() { + var x int + p := noleak(&x) // ERROR "&x does not escape" + _ = p +} + +func f2() { + var x int + p := leaktoret(&x) // ERROR "&x does not escape" + _ = p +} + +func f3() { + var x int // ERROR "moved to heap: x" + p := leaktoret(&x) // ERROR "&x escapes to heap" + gp = p +} + +func f4() { + var x int // ERROR "moved to heap: x" + p, q := leaktoret2(&x) // ERROR "&x escapes to heap" + gp = p + gp = q +} + +func f5() { + var x int + leaktoret22(leaktoret2(&x)) // ERROR "&x does not escape" +} + +func f6() { + var x int // ERROR "moved to heap: x" + px1, px2 := leaktoret22(leaktoret2(&x)) // ERROR "&x escapes to heap" + gp = px1 + _ = px2 +} + +type T struct{ x int } + +func (t *T) Foo(u int) (*T, bool) { // ERROR "leaking param: t to result" + t.x += u + return t, true +} + +func f7() *T { + r, _ := new(T).Foo(42) // ERROR "new.T. escapes to heap" + return r +} + +func leakrecursive1(p, q *int) (*int, *int) { // ERROR "leaking param: p" "leaking param: q" + return leakrecursive2(q, p) +} + +func leakrecursive2(p, q *int) (*int, *int) { // ERROR "leaking param: p" "leaking param: q" + if *p > *q { + return leakrecursive1(q, p) + } + // without this, leakrecursive? are safe for p and q, b/c in fact their graph does not have leaking edges. + return p, q +} + + +var global interface{} + +type T1 struct { + X *int +} + +type T2 struct { + Y *T1 +} + +func f8(p *T1) (k T2) { // ERROR "leaking param: p to result k" "leaking param: p" + if p == nil { + k = T2{} + return + } + + global = p // should make p leak always + return T2{p} +} + +func f9() { + var j T1 // ERROR "moved to heap: j" + f8(&j) // ERROR "&j escapes to heap" +} 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 +} diff --git a/test/float_lit.go b/test/float_lit.go index 2912c3749..4efae2362 100644 --- a/test/float_lit.go +++ b/test/float_lit.go @@ -196,4 +196,8 @@ func main() { if !close(-210.012e19, -210012, 1000, 19) { print("-210.012e19 is ", -210.012e19, "\n") } + + if bad { + panic("float_lit") + } } diff --git a/test/floatcmp.go b/test/floatcmp.go index f9f59a937..6c424ccd9 100644 --- a/test/floatcmp.go +++ b/test/floatcmp.go @@ -87,4 +87,7 @@ func main() { println(t.name, "=", t.expr, "want", t.want) } } + if bad { + panic("floatcmp failed") + } } diff --git a/test/func7.go b/test/func7.go index 6f6766f29..2d646b678 100644 --- a/test/func7.go +++ b/test/func7.go @@ -17,7 +17,7 @@ func f() int { func g() int { if !calledf { - println("BUG: func7 - called g before f") + panic("BUG: func7 - called g before f") } return 0 } @@ -28,4 +28,3 @@ func main() { panic("wrong answer") } } - diff --git a/test/func8.go b/test/func8.go index 7defe265b..13051802e 100644 --- a/test/func8.go +++ b/test/func8.go @@ -37,13 +37,13 @@ func y() string { func main() { if f() == g() { - println("wrong f,g order") + panic("wrong f,g order") } if x() == (y() == "abc") { panic("wrong compare") } if xy != "xy" { - println("wrong x,y order") + panic("wrong x,y order") } } diff --git a/test/golden.out b/test/golden.out index 376af8e53..742a5d3f6 100644 --- a/test/golden.out +++ b/test/golden.out @@ -16,7 +16,7 @@ == fixedbugs/ =========== fixedbugs/bug429.go -throw: all goroutines are asleep - deadlock! +fatal error: all goroutines are asleep - deadlock! == bugs/ diff --git a/test/import2.dir/import2.go b/test/import2.dir/import2.go new file mode 100644 index 000000000..8bb1eb919 --- /dev/null +++ b/test/import2.dir/import2.go @@ -0,0 +1,42 @@ +// 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. + +// Various declarations of exported variables and functions. + +package p + +var C1 chan <- chan int = (chan<- (chan int))(nil) +var C2 chan (<- chan int) = (chan (<-chan int))(nil) +var C3 <- chan chan int = (<-chan (chan int))(nil) +var C4 chan chan <- int = (chan (chan<- int))(nil) + +var C5 <- chan <- chan int = (<-chan (<-chan int))(nil) +var C6 chan <- <- chan int = (chan<- (<-chan int))(nil) +var C7 chan <- chan <- int = (chan<- (chan<- int))(nil) + +var C8 <- chan <- chan chan int = (<-chan (<-chan (chan int)))(nil) +var C9 <- chan chan <- chan int = (<-chan (chan<- (chan int)))(nil) +var C10 chan <- <- chan chan int = (chan<- (<-chan (chan int)))(nil) +var C11 chan <- chan <- chan int = (chan<- (chan<- (chan int)))(nil) +var C12 chan chan <- <- chan int = (chan (chan<- (<-chan int)))(nil) +var C13 chan chan <- chan <- int = (chan (chan<- (chan<- int)))(nil) + +var R1 chan<- (chan int) = (chan <- chan int)(nil) +var R3 <-chan (chan int) = (<- chan chan int)(nil) +var R4 chan (chan<- int) = (chan chan <- int)(nil) + +var R5 <-chan (<-chan int) = (<- chan <- chan int)(nil) +var R6 chan<- (<-chan int) = (chan <- <- chan int)(nil) +var R7 chan<- (chan<- int) = (chan <- chan <- int)(nil) + +var R8 <-chan (<-chan (chan int)) = (<- chan <- chan chan int)(nil) +var R9 <-chan (chan<- (chan int)) = (<- chan chan <- chan int)(nil) +var R10 chan<- (<-chan (chan int)) = (chan <- <- chan chan int)(nil) +var R11 chan<- (chan<- (chan int)) = (chan <- chan <- chan int)(nil) +var R12 chan (chan<- (<-chan int)) = (chan chan <- <- chan int)(nil) +var R13 chan (chan<- (chan<- int)) = (chan chan <- chan <- int)(nil) + +var F1 func() func() int +func F2() func() func() int +func F3(func() func() int) diff --git a/test/import3.go b/test/import2.dir/import3.go index 274fcfe42..d7fe37b19 100644 --- a/test/import3.go +++ b/test/import2.dir/import3.go @@ -1,5 +1,3 @@ -// $G $D/import2.go && $G $D/$F.go - // 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/import2.go b/test/import2.go index 5c275f34b..f8d0b0a0f 100644 --- a/test/import2.go +++ b/test/import2.go @@ -1,45 +1,8 @@ -// skip # used by import3 +// compiledir // 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. -// Various declarations of exported variables and functions. -// Imported by import3.go. - -package p - -var C1 chan <- chan int = (chan<- (chan int))(nil) -var C2 chan (<- chan int) = (chan (<-chan int))(nil) -var C3 <- chan chan int = (<-chan (chan int))(nil) -var C4 chan chan <- int = (chan (chan<- int))(nil) - -var C5 <- chan <- chan int = (<-chan (<-chan int))(nil) -var C6 chan <- <- chan int = (chan<- (<-chan int))(nil) -var C7 chan <- chan <- int = (chan<- (chan<- int))(nil) - -var C8 <- chan <- chan chan int = (<-chan (<-chan (chan int)))(nil) -var C9 <- chan chan <- chan int = (<-chan (chan<- (chan int)))(nil) -var C10 chan <- <- chan chan int = (chan<- (<-chan (chan int)))(nil) -var C11 chan <- chan <- chan int = (chan<- (chan<- (chan int)))(nil) -var C12 chan chan <- <- chan int = (chan (chan<- (<-chan int)))(nil) -var C13 chan chan <- chan <- int = (chan (chan<- (chan<- int)))(nil) - -var R1 chan<- (chan int) = (chan <- chan int)(nil) -var R3 <-chan (chan int) = (<- chan chan int)(nil) -var R4 chan (chan<- int) = (chan chan <- int)(nil) - -var R5 <-chan (<-chan int) = (<- chan <- chan int)(nil) -var R6 chan<- (<-chan int) = (chan <- <- chan int)(nil) -var R7 chan<- (chan<- int) = (chan <- chan <- int)(nil) - -var R8 <-chan (<-chan (chan int)) = (<- chan <- chan chan int)(nil) -var R9 <-chan (chan<- (chan int)) = (<- chan chan <- chan int)(nil) -var R10 chan<- (<-chan (chan int)) = (chan <- <- chan chan int)(nil) -var R11 chan<- (chan<- (chan int)) = (chan <- chan <- chan int)(nil) -var R12 chan (chan<- (<-chan int)) = (chan chan <- <- chan int)(nil) -var R13 chan (chan<- (chan<- int)) = (chan chan <- chan <- int)(nil) - -var F1 func() func() int -func F2() func() func() int -func F3(func() func() int) +// Tests that export data does not corrupt type syntax. +package ignored diff --git a/test/import4.dir/empty.go b/test/import4.dir/empty.go new file mode 100644 index 000000000..c8214f36d --- /dev/null +++ b/test/import4.dir/empty.go @@ -0,0 +1,10 @@ +// 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 P + +import ( ) +const ( ) +var ( ) +type ( ) diff --git a/test/import4.dir/import4.go b/test/import4.dir/import4.go new file mode 100644 index 000000000..b9f973f17 --- /dev/null +++ b/test/import4.dir/import4.go @@ -0,0 +1,24 @@ +// 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. + +// Verify that various kinds of "imported and not used" +// errors are caught by the compiler. +// Does not compile. + +package main + +// standard +import "fmt" // ERROR "imported and not used.*fmt" + +// renamed +import X "math" // ERROR "imported and not used.*math" + +// import dot +import . "bufio" // ERROR "imported and not used.*bufio" + +// again, package without anything in it +import "./empty" // ERROR "imported and not used.*empty" +import Z "./empty" // ERROR "imported and not used.*empty" +import . "./empty" // ERROR "imported and not used.*empty" + diff --git a/test/import4.go b/test/import4.go index cbfebf7e1..875bf8943 100644 --- a/test/import4.go +++ b/test/import4.go @@ -1,4 +1,4 @@ -// $G $D/empty.go && errchk $G $D/$F.go +// errorcheckdir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -8,19 +8,4 @@ // errors are caught by the compiler. // Does not compile. -package main - -// standard -import "fmt" // ERROR "imported and not used.*fmt" - -// renamed -import X "math" // ERROR "imported and not used.*math" - -// import dot -import . "bufio" // ERROR "imported and not used.*bufio" - -// again, package without anything in it -import "./empty" // ERROR "imported and not used.*empty" -import Z "./empty" // ERROR "imported and not used.*empty" -import . "./empty" // ERROR "imported and not used.*empty" - +package ignored diff --git a/test/index.go b/test/index.go index f9e2413c1..daab45f7a 100644 --- a/test/index.go +++ b/test/index.go @@ -1,23 +1,19 @@ -// $G $D/$F.go && $L $F.$A && -// ./$A.out -pass 0 >tmp.go && $G tmp.go && $L -o $A.out1 tmp.$A && ./$A.out1 && -// ./$A.out -pass 1 >tmp.go && errchk $G -e tmp.go && -// ./$A.out -pass 2 >tmp.go && errchk $G -e tmp.go -// rm -f tmp.go $A.out1 +// skip // 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. // Generate test of index and slice bounds checks. -// The output is compiled and run. +// The actual tests are index0.go, index1.go, index2.go. package main import ( "bufio" - "flag" "fmt" "os" + "unsafe" ) const prolog = ` @@ -151,14 +147,13 @@ func bug() { func main() { ` -// Passes: +// pass variable set in index[012].go // 0 - dynamic checks // 1 - static checks of invalid constants (cannot assign to types) // 2 - static checks of array bounds -var pass = flag.Int("pass", 0, "which test (0,1,2)") func testExpr(b *bufio.Writer, expr string) { - if *pass == 0 { + if pass == 0 { fmt.Fprintf(b, "\ttest(func(){use(%s)}, %q)\n", expr, expr) } else { fmt.Fprintf(b, "\tuse(%s) // ERROR \"index|overflow\"\n", expr) @@ -168,12 +163,10 @@ func testExpr(b *bufio.Writer, expr string) { func main() { b := bufio.NewWriter(os.Stdout) - flag.Parse() - - if *pass == 0 { - fmt.Fprint(b, "// $G $D/$F.go && $L $F.$A && ./$A.out\n\n") + if pass == 0 { + fmt.Fprint(b, "// run\n\n") } else { - fmt.Fprint(b, "// errchk $G -e $D/$F.go\n\n") + fmt.Fprint(b, "// errorcheck\n\n") } fmt.Fprint(b, prolog) @@ -221,6 +214,11 @@ func main() { // the next pass from running. // So run it as a separate check. thisPass = 1 + } else if a == "s" && n == "" && (i == "i64big" || i == "i64bigger") && unsafe.Sizeof(int(0)) > 4 { + // If int is 64 bits, these huge + // numbers do fit in an int, so they + // are not rejected at compile time. + thisPass = 0 } else { thisPass = 2 } @@ -232,7 +230,7 @@ func main() { } // Only print the test case if it is appropriate for this pass. - if thisPass == *pass { + if thisPass == pass { pae := p+a+e+big cni := c+n+i diff --git a/test/index0.go b/test/index0.go new file mode 100644 index 000000000..04a16198d --- /dev/null +++ b/test/index0.go @@ -0,0 +1,12 @@ +// runoutput ./index.go + +// 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. + +// Generate test of index and slice bounds checks. +// The output is compiled and run. + +package main + +const pass = 0 diff --git a/test/index1.go b/test/index1.go new file mode 100644 index 000000000..e28efa35f --- /dev/null +++ b/test/index1.go @@ -0,0 +1,12 @@ +// errorcheckoutput ./index.go + +// 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. + +// Generate test of index and slice bounds checks. +// The output is error checked. + +package main + +const pass = 1 diff --git a/test/index2.go b/test/index2.go new file mode 100644 index 000000000..a7107cc05 --- /dev/null +++ b/test/index2.go @@ -0,0 +1,12 @@ +// errorcheckoutput ./index.go + +// 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. + +// Generate test of index and slice bounds checks. +// The output is error checked. + +package main + +const pass = 2 diff --git a/test/init1.go b/test/init1.go index a888ad744..f6eda6edf 100644 --- a/test/init1.go +++ b/test/init1.go @@ -33,6 +33,7 @@ func init() { sys1 := memstats.Sys if sys1-sys > chunk*50 { println("allocated 1000 chunks of", chunk, "and used ", sys1-sys, "memory") + panic("init1") } } diff --git a/test/initializerr.go b/test/initializerr.go index 48908c347..ca0541455 100644 --- a/test/initializerr.go +++ b/test/initializerr.go @@ -26,3 +26,15 @@ var a5 = []byte { x: 2 } // ERROR "index" var ok1 = S { } // should be ok var ok2 = T { S: ok1 } // should be ok + +// These keys can be computed at compile time but they are +// not constants as defined by the spec, so they do not trigger +// compile-time errors about duplicate key values. +// See issue 4555. + +type Key struct {X, Y int} + +var _ = map[Key]string{ + Key{1,2}: "hello", + Key{1,2}: "world", +} diff --git a/test/interface/embed0.go b/test/interface/embed1.dir/embed0.go index e2ee20ade..728bec74e 100644 --- a/test/interface/embed0.go +++ b/test/interface/embed1.dir/embed0.go @@ -1,5 +1,3 @@ -// skip # used by embed1.go - // 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/interface/embed1.dir/embed1.go b/test/interface/embed1.dir/embed1.go new file mode 100644 index 000000000..7dfb1dbc0 --- /dev/null +++ b/test/interface/embed1.dir/embed1.go @@ -0,0 +1,43 @@ +// 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. + +// Test that embedded interface types can have local methods. + +package main + +import "./embed0" + +type T int +func (t T) m() {} + +type I interface { m() } +type J interface { I } + +type PI interface { p.I } +type PJ interface { p.J } + +func main() { + var i I + var j J + var t T + i = t + j = t + _ = i + _ = j + i = j + _ = i + j = i + _ = j + var pi PI + var pj PJ + var pt p.T + pi = pt + pj = pt + _ = pi + _ = pj + pi = pj + _ = pi + pj = pi + _ = pj +} diff --git a/test/interface/embed1.go b/test/interface/embed1.go index ee502a162..784b82bb0 100644 --- a/test/interface/embed1.go +++ b/test/interface/embed1.go @@ -1,4 +1,4 @@ -// $G $D/embed0.go && $G $D/$F.go && $L $F.$A && ./$A.out +// rundir // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -6,40 +6,4 @@ // Test that embedded interface types can have local methods. -package main - -import "./embed0" - -type T int -func (t T) m() {} - -type I interface { m() } -type J interface { I } - -type PI interface { p.I } -type PJ interface { p.J } - -func main() { - var i I - var j J - var t T - i = t - j = t - _ = i - _ = j - i = j - _ = i - j = i - _ = j - var pi PI - var pj PJ - var pt p.T - pi = pt - pj = pt - _ = pi - _ = pj - pi = pj - _ = pi - pj = pi - _ = pj -} +package ignored diff --git a/test/interface/explicit.go b/test/interface/explicit.go index d19480a68..eb81156e0 100644 --- a/test/interface/explicit.go +++ b/test/interface/explicit.go @@ -15,6 +15,10 @@ type T struct { var t *T +type X int + +func (x *X) M() {} + type I interface { M() } @@ -40,7 +44,7 @@ func main() { // because i has an extra method // that t does not, so i cannot contain a t. i = t // ERROR "incompatible|missing M method" - t = i // ERROR "incompatible|need type assertion" + t = i // ERROR "incompatible|assignment$" i = i2 // ok i2 = i // ERROR "incompatible|missing N method" @@ -66,6 +70,8 @@ func (Int) M(float64) {} var _ = m.(Int) // ERROR "impossible type assertion" +var _ = m.(X) // ERROR "pointer receiver" + var ii int var jj Int diff --git a/test/interface/private1.go b/test/interface/private.dir/private1.go index 3281c38be..75eee51f5 100644 --- a/test/interface/private1.go +++ b/test/interface/private.dir/private1.go @@ -1,5 +1,3 @@ -// skip # used by private.go - // 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/interface/private.dir/prog.go b/test/interface/private.dir/prog.go new file mode 100644 index 000000000..abea7d625 --- /dev/null +++ b/test/interface/private.dir/prog.go @@ -0,0 +1,33 @@ +// 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 that unexported methods are not visible outside the package. +// Does not compile. + +package main + +import "./private1" + +type Exported interface { + private() +} + +type Implementation struct{} + +func (p *Implementation) private() {} + +func main() { + var x Exported + x = new(Implementation) + x.private() + + var px p.Exported + px = p.X + + px.private() // ERROR "private" + + px = new(Implementation) // ERROR "private" + + x = px // ERROR "private" +} diff --git a/test/interface/private.go b/test/interface/private.go index 14dfc1ae5..a0da249c9 100644 --- a/test/interface/private.go +++ b/test/interface/private.go @@ -1,4 +1,4 @@ -// $G $D/${F}1.go && errchk $G $D/$F.go +// errorcheckdir // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -7,29 +7,4 @@ // Test that unexported methods are not visible outside the package. // Does not compile. -package main - -import "./private1" - -type Exported interface { - private() -} - -type Implementation struct{} - -func (p *Implementation) private() {} - -func main() { - var x Exported - x = new(Implementation) - x.private() - - var px p.Exported - px = p.X - - px.private() // ERROR "private" - - px = new(Implementation) // ERROR "private" - - x = px // ERROR "private" -} +package ignored diff --git a/test/interface/recursive1.dir/recursive1.go b/test/interface/recursive1.dir/recursive1.go new file mode 100644 index 000000000..441f0ecaa --- /dev/null +++ b/test/interface/recursive1.dir/recursive1.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. + +// Mutually recursive type definitions imported and used by recursive1.go. + +package p + +type I1 interface { + F() I2 +} + +type I2 interface { + I1 +} diff --git a/test/interface/recursive2.go b/test/interface/recursive1.dir/recursive2.go index 5129ceb02..e8048c672 100644 --- a/test/interface/recursive2.go +++ b/test/interface/recursive1.dir/recursive2.go @@ -1,5 +1,3 @@ -// $G $D/recursive1.go && $G $D/$F.go - // 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/interface/recursive1.go b/test/interface/recursive1.go index cc3cdc37f..62f610884 100644 --- a/test/interface/recursive1.go +++ b/test/interface/recursive1.go @@ -1,4 +1,4 @@ -// skip # used by recursive2 +// compiledir // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -6,12 +6,4 @@ // Mutually recursive type definitions imported and used by recursive1.go. -package p - -type I1 interface { - F() I2 -} - -type I2 interface { - I1 -} +package ignored diff --git a/test/linkx.go b/test/linkx.go index d2c954567..12d446ffc 100644 --- a/test/linkx.go +++ b/test/linkx.go @@ -1,5 +1,8 @@ // $G $D/$F.go && $L -X main.tbd hello $F.$A && ./$A.out +// 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/literal.go b/test/literal.go index ba185fc9a..c3d6bc123 100644 --- a/test/literal.go +++ b/test/literal.go @@ -24,7 +24,6 @@ func equal(a, b float32) bool { return a == b } - func main() { // bool var t bool = true @@ -225,6 +224,6 @@ func main() { assert(sj0 == sj3, "sj3") if nbad > 0 { - println() + panic("literal failed") } } diff --git a/test/map.go b/test/map.go index 6dec0dfd7..041c8fbbe 100644 --- a/test/map.go +++ b/test/map.go @@ -41,7 +41,7 @@ func testbasic() { for i := 0; i < len(mlit); i++ { s := string([]byte{byte(i) + '0'}) if mlit[s] != i { - fmt.Printf("mlit[%s] = %d\n", s, mlit[s]) + panic(fmt.Sprintf("mlit[%s] = %d\n", s, mlit[s])) } } @@ -102,46 +102,46 @@ func testbasic() { // test len if len(mib) != count { - fmt.Printf("len(mib) = %d\n", len(mib)) + panic(fmt.Sprintf("len(mib) = %d\n", len(mib))) } if len(mii) != count { - fmt.Printf("len(mii) = %d\n", len(mii)) + panic(fmt.Sprintf("len(mii) = %d\n", len(mii))) } if len(mfi) != count { - fmt.Printf("len(mfi) = %d\n", len(mfi)) + panic(fmt.Sprintf("len(mfi) = %d\n", len(mfi))) } if len(mif) != count { - fmt.Printf("len(mif) = %d\n", len(mif)) + panic(fmt.Sprintf("len(mif) = %d\n", len(mif))) } if len(msi) != count { - fmt.Printf("len(msi) = %d\n", len(msi)) + panic(fmt.Sprintf("len(msi) = %d\n", len(msi))) } if len(mis) != count { - fmt.Printf("len(mis) = %d\n", len(mis)) + panic(fmt.Sprintf("len(mis) = %d\n", len(mis))) } if len(mss) != count { - fmt.Printf("len(mss) = %d\n", len(mss)) + panic(fmt.Sprintf("len(mss) = %d\n", len(mss))) } if len(mspa) != count { - fmt.Printf("len(mspa) = %d\n", len(mspa)) + panic(fmt.Sprintf("len(mspa) = %d\n", len(mspa))) } if len(mipT) != count { - fmt.Printf("len(mipT) = %d\n", len(mipT)) + panic(fmt.Sprintf("len(mipT) = %d\n", len(mipT))) } if len(mpTi) != count { - fmt.Printf("len(mpTi) = %d\n", len(mpTi)) + panic(fmt.Sprintf("len(mpTi) = %d\n", len(mpTi))) } // if len(mti) != count { - // fmt.Printf("len(mti) = %d\n", len(mti)) + // panic(fmt.Sprintf("len(mti) = %d\n", len(mti))) // } if len(mipM) != count { - fmt.Printf("len(mipM) = %d\n", len(mipM)) + panic(fmt.Sprintf("len(mipM) = %d\n", len(mipM))) } // if len(mti) != count { - // fmt.Printf("len(mti) = %d\n", len(mti)) + // panic(fmt.Sprintf("len(mti) = %d\n", len(mti))) // } if len(mit) != count { - fmt.Printf("len(mit) = %d\n", len(mit)) + panic(fmt.Sprintf("len(mit) = %d\n", len(mit))) } // test construction directly @@ -151,48 +151,48 @@ func testbasic() { f := float32(i) // BUG m := M(i, i+1) if mib[i] != (i != 0) { - fmt.Printf("mib[%d] = %t\n", i, mib[i]) + panic(fmt.Sprintf("mib[%d] = %t\n", i, mib[i])) } if mii[i] != 10*i { - fmt.Printf("mii[%d] = %d\n", i, mii[i]) + panic(fmt.Sprintf("mii[%d] = %d\n", i, mii[i])) } if mfi[f] != 10*i { - fmt.Printf("mfi[%d] = %d\n", i, mfi[f]) + panic(fmt.Sprintf("mfi[%d] = %d\n", i, mfi[f])) } if mif[i] != 10.0*f { - fmt.Printf("mif[%d] = %g\n", i, mif[i]) + panic(fmt.Sprintf("mif[%d] = %g\n", i, mif[i])) } if mis[i] != s { - fmt.Printf("mis[%d] = %s\n", i, mis[i]) + panic(fmt.Sprintf("mis[%d] = %s\n", i, mis[i])) } if msi[s] != i { - fmt.Printf("msi[%s] = %d\n", s, msi[s]) + panic(fmt.Sprintf("msi[%s] = %d\n", s, msi[s])) } if mss[s] != s10 { - fmt.Printf("mss[%s] = %g\n", s, mss[s]) + panic(fmt.Sprintf("mss[%s] = %g\n", s, mss[s])) } for j := 0; j < len(mspa[s]); j++ { if mspa[s][j] != s10 { - fmt.Printf("mspa[%s][%d] = %s\n", s, j, mspa[s][j]) + panic(fmt.Sprintf("mspa[%s][%d] = %s\n", s, j, mspa[s][j])) } } if mipT[i].i != int64(i) || mipT[i].f != f { - fmt.Printf("mipT[%d] = %v\n", i, mipT[i]) + panic(fmt.Sprintf("mipT[%d] = %v\n", i, mipT[i])) } if mpTi[apT[i]] != i { - fmt.Printf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]]) + panic(fmt.Sprintf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]])) } // if(mti[t] != i) { - // fmt.Printf("mti[%s] = %s\n", s, mti[t]) + // panic(fmt.Sprintf("mti[%s] = %s\n", s, mti[t])) // } if mipM[i][i] != i+1 { - fmt.Printf("mipM[%d][%d] = %d\n", i, i, mipM[i][i]) + panic(fmt.Sprintf("mipM[%d][%d] = %d\n", i, i, mipM[i][i])) } // if(mti[t] != i) { - // fmt.Printf("mti[%v] = %d\n", t, mti[t]) + // panic(fmt.Sprintf("mti[%v] = %d\n", t, mti[t])) // } if mit[i].i != int64(i) || mit[i].f != f { - fmt.Printf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f) + panic(fmt.Sprintf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f)) } } @@ -204,131 +204,131 @@ func testbasic() { { _, b := mib[i] if !b { - fmt.Printf("tuple existence decl: mib[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mib[%d]\n", i)) } _, b = mib[i] if !b { - fmt.Printf("tuple existence assign: mib[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mib[%d]\n", i)) } } { _, b := mii[i] if !b { - fmt.Printf("tuple existence decl: mii[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mii[%d]\n", i)) } _, b = mii[i] if !b { - fmt.Printf("tuple existence assign: mii[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mii[%d]\n", i)) } } { _, b := mfi[f] if !b { - fmt.Printf("tuple existence decl: mfi[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mfi[%d]\n", i)) } _, b = mfi[f] if !b { - fmt.Printf("tuple existence assign: mfi[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mfi[%d]\n", i)) } } { _, b := mif[i] if !b { - fmt.Printf("tuple existence decl: mif[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mif[%d]\n", i)) } _, b = mif[i] if !b { - fmt.Printf("tuple existence assign: mif[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mif[%d]\n", i)) } } { _, b := mis[i] if !b { - fmt.Printf("tuple existence decl: mis[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mis[%d]\n", i)) } _, b = mis[i] if !b { - fmt.Printf("tuple existence assign: mis[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mis[%d]\n", i)) } } { _, b := msi[s] if !b { - fmt.Printf("tuple existence decl: msi[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: msi[%d]\n", i)) } _, b = msi[s] if !b { - fmt.Printf("tuple existence assign: msi[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: msi[%d]\n", i)) } } { _, b := mss[s] if !b { - fmt.Printf("tuple existence decl: mss[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mss[%d]\n", i)) } _, b = mss[s] if !b { - fmt.Printf("tuple existence assign: mss[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mss[%d]\n", i)) } } { _, b := mspa[s] if !b { - fmt.Printf("tuple existence decl: mspa[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mspa[%d]\n", i)) } _, b = mspa[s] if !b { - fmt.Printf("tuple existence assign: mspa[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mspa[%d]\n", i)) } } { _, b := mipT[i] if !b { - fmt.Printf("tuple existence decl: mipT[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mipT[%d]\n", i)) } _, b = mipT[i] if !b { - fmt.Printf("tuple existence assign: mipT[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mipT[%d]\n", i)) } } { _, b := mpTi[apT[i]] if !b { - fmt.Printf("tuple existence decl: mpTi[apT[%d]]\n", i) + panic(fmt.Sprintf("tuple existence decl: mpTi[apT[%d]]\n", i)) } _, b = mpTi[apT[i]] if !b { - fmt.Printf("tuple existence assign: mpTi[apT[%d]]\n", i) + panic(fmt.Sprintf("tuple existence assign: mpTi[apT[%d]]\n", i)) } } { _, b := mipM[i] if !b { - fmt.Printf("tuple existence decl: mipM[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mipM[%d]\n", i)) } _, b = mipM[i] if !b { - fmt.Printf("tuple existence assign: mipM[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mipM[%d]\n", i)) } } { _, b := mit[i] if !b { - fmt.Printf("tuple existence decl: mit[%d]\n", i) + panic(fmt.Sprintf("tuple existence decl: mit[%d]\n", i)) } _, b = mit[i] if !b { - fmt.Printf("tuple existence assign: mit[%d]\n", i) + panic(fmt.Sprintf("tuple existence assign: mit[%d]\n", i)) } } // { // _, b := mti[t] // if !b { - // fmt.Printf("tuple existence decl: mti[%d]\n", i) + // panic(fmt.Sprintf("tuple existence decl: mti[%d]\n", i)) // } // _, b = mti[t] // if !b { - // fmt.Printf("tuple existence assign: mti[%d]\n", i) + // panic(fmt.Sprintf("tuple existence assign: mti[%d]\n", i)) // } // } } @@ -341,131 +341,131 @@ func testbasic() { { _, b := mib[i] if b { - fmt.Printf("tuple nonexistence decl: mib[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mib[%d]", i)) } _, b = mib[i] if b { - fmt.Printf("tuple nonexistence assign: mib[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mib[%d]", i)) } } { _, b := mii[i] if b { - fmt.Printf("tuple nonexistence decl: mii[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mii[%d]", i)) } _, b = mii[i] if b { - fmt.Printf("tuple nonexistence assign: mii[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mii[%d]", i)) } } { _, b := mfi[f] if b { - fmt.Printf("tuple nonexistence decl: mfi[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mfi[%d]", i)) } _, b = mfi[f] if b { - fmt.Printf("tuple nonexistence assign: mfi[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mfi[%d]", i)) } } { _, b := mif[i] if b { - fmt.Printf("tuple nonexistence decl: mif[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mif[%d]", i)) } _, b = mif[i] if b { - fmt.Printf("tuple nonexistence assign: mif[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mif[%d]", i)) } } { _, b := mis[i] if b { - fmt.Printf("tuple nonexistence decl: mis[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mis[%d]", i)) } _, b = mis[i] if b { - fmt.Printf("tuple nonexistence assign: mis[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mis[%d]", i)) } } { _, b := msi[s] if b { - fmt.Printf("tuple nonexistence decl: msi[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: msi[%d]", i)) } _, b = msi[s] if b { - fmt.Printf("tuple nonexistence assign: msi[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: msi[%d]", i)) } } { _, b := mss[s] if b { - fmt.Printf("tuple nonexistence decl: mss[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mss[%d]", i)) } _, b = mss[s] if b { - fmt.Printf("tuple nonexistence assign: mss[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mss[%d]", i)) } } { _, b := mspa[s] if b { - fmt.Printf("tuple nonexistence decl: mspa[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mspa[%d]", i)) } _, b = mspa[s] if b { - fmt.Printf("tuple nonexistence assign: mspa[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mspa[%d]", i)) } } { _, b := mipT[i] if b { - fmt.Printf("tuple nonexistence decl: mipT[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mipT[%d]", i)) } _, b = mipT[i] if b { - fmt.Printf("tuple nonexistence assign: mipT[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mipT[%d]", i)) } } { _, b := mpTi[apT[i]] if b { - fmt.Printf("tuple nonexistence decl: mpTi[apt[%d]]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mpTi[apt[%d]]", i)) } _, b = mpTi[apT[i]] if b { - fmt.Printf("tuple nonexistence assign: mpTi[apT[%d]]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mpTi[apT[%d]]", i)) } } { _, b := mipM[i] if b { - fmt.Printf("tuple nonexistence decl: mipM[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mipM[%d]", i)) } _, b = mipM[i] if b { - fmt.Printf("tuple nonexistence assign: mipM[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mipM[%d]", i)) } } // { // _, b := mti[t] // if b { - // fmt.Printf("tuple nonexistence decl: mti[%d]", i) + // panic(fmt.Sprintf("tuple nonexistence decl: mti[%d]", i)) // } // _, b = mti[t] // if b { - // fmt.Printf("tuple nonexistence assign: mti[%d]", i) + // panic(fmt.Sprintf("tuple nonexistence assign: mti[%d]", i)) // } // } { _, b := mit[i] if b { - fmt.Printf("tuple nonexistence decl: mit[%d]", i) + panic(fmt.Sprintf("tuple nonexistence decl: mit[%d]", i)) } _, b = mit[i] if b { - fmt.Printf("tuple nonexistence assign: mit[%d]", i) + panic(fmt.Sprintf("tuple nonexistence assign: mit[%d]", i)) } } } @@ -475,21 +475,25 @@ func testbasic() { s := strconv.Itoa(i) mspa[s][i%2] = "deleted" if mspa[s][i%2] != "deleted" { - fmt.Printf("update mspa[%s][%d] = %s\n", s, i%2, mspa[s][i%2]) + panic(fmt.Sprintf("update mspa[%s][%d] = %s\n", s, i%2, mspa[s][i%2])) + } mipT[i].i += 1 if mipT[i].i != int64(i)+1 { - fmt.Printf("update mipT[%d].i = %d\n", i, mipT[i].i) + panic(fmt.Sprintf("update mipT[%d].i = %d\n", i, mipT[i].i)) + } mipT[i].f = float32(i + 1) if mipT[i].f != float32(i+1) { - fmt.Printf("update mipT[%d].f = %g\n", i, mipT[i].f) + panic(fmt.Sprintf("update mipT[%d].f = %g\n", i, mipT[i].f)) + } mipM[i][i]++ if mipM[i][i] != (i+1)+1 { - fmt.Printf("update mipM[%d][%d] = %d\n", i, i, mipM[i][i]) + panic(fmt.Sprintf("update mipM[%d][%d] = %d\n", i, i, mipM[i][i])) + } } @@ -519,29 +523,29 @@ func testfloat() { nanb: "NaN", } if m[pz] != "+0" { - fmt.Println("float32 map cannot read back m[+0]:", m[pz]) + panic(fmt.Sprintln("float32 map cannot read back m[+0]:", m[pz])) } if m[nz] != "+0" { - fmt.Println("float32 map does not treat", pz, "and", nz, "as equal for read") - fmt.Println("float32 map does not treat -0 and +0 as equal for read") + fmt.Sprintln("float32 map does not treat", pz, "and", nz, "as equal for read") + panic(fmt.Sprintln("float32 map does not treat -0 and +0 as equal for read")) } m[nz] = "-0" if m[pz] != "-0" { - fmt.Println("float32 map does not treat -0 and +0 as equal for write") + panic(fmt.Sprintln("float32 map does not treat -0 and +0 as equal for write")) } if _, ok := m[nana]; ok { - fmt.Println("float32 map allows NaN lookup (a)") + panic(fmt.Sprintln("float32 map allows NaN lookup (a)")) } if _, ok := m[nanb]; ok { - fmt.Println("float32 map allows NaN lookup (b)") + panic(fmt.Sprintln("float32 map allows NaN lookup (b)")) } if len(m) != 3 { - fmt.Println("float32 map should have 3 entries:", m) + panic(fmt.Sprintln("float32 map should have 3 entries:", m)) } m[nana] = "NaN" m[nanb] = "NaN" if len(m) != 5 { - fmt.Println("float32 map should have 5 entries:", m) + panic(fmt.Sprintln("float32 map should have 5 entries:", m)) } } @@ -559,25 +563,25 @@ func testfloat() { nanb: "NaN", } if m[nz] != "+0" { - fmt.Println("float64 map does not treat -0 and +0 as equal for read") + panic(fmt.Sprintln("float64 map does not treat -0 and +0 as equal for read")) } m[nz] = "-0" if m[pz] != "-0" { - fmt.Println("float64 map does not treat -0 and +0 as equal for write") + panic(fmt.Sprintln("float64 map does not treat -0 and +0 as equal for write")) } if _, ok := m[nana]; ok { - fmt.Println("float64 map allows NaN lookup (a)") + panic(fmt.Sprintln("float64 map allows NaN lookup (a)")) } if _, ok := m[nanb]; ok { - fmt.Println("float64 map allows NaN lookup (b)") + panic(fmt.Sprintln("float64 map allows NaN lookup (b)")) } if len(m) != 3 { - fmt.Println("float64 map should have 3 entries:", m) + panic(fmt.Sprintln("float64 map should have 3 entries:", m)) } m[nana] = "NaN" m[nanb] = "NaN" if len(m) != 5 { - fmt.Println("float64 map should have 5 entries:", m) + panic(fmt.Sprintln("float64 map should have 5 entries:", m)) } } @@ -595,25 +599,25 @@ func testfloat() { nanb: "NaN", } if m[nz] != "+0" { - fmt.Println("complex64 map does not treat -0 and +0 as equal for read") + panic(fmt.Sprintln("complex64 map does not treat -0 and +0 as equal for read")) } m[nz] = "-0" if m[pz] != "-0" { - fmt.Println("complex64 map does not treat -0 and +0 as equal for write") + panic(fmt.Sprintln("complex64 map does not treat -0 and +0 as equal for write")) } if _, ok := m[nana]; ok { - fmt.Println("complex64 map allows NaN lookup (a)") + panic(fmt.Sprintln("complex64 map allows NaN lookup (a)")) } if _, ok := m[nanb]; ok { - fmt.Println("complex64 map allows NaN lookup (b)") + panic(fmt.Sprintln("complex64 map allows NaN lookup (b)")) } if len(m) != 3 { - fmt.Println("complex64 map should have 3 entries:", m) + panic(fmt.Sprintln("complex64 map should have 3 entries:", m)) } m[nana] = "NaN" m[nanb] = "NaN" if len(m) != 5 { - fmt.Println("complex64 map should have 5 entries:", m) + panic(fmt.Sprintln("complex64 map should have 5 entries:", m)) } } @@ -631,25 +635,25 @@ func testfloat() { nanb: "NaN", } if m[nz] != "+0" { - fmt.Println("complex128 map does not treat -0 and +0 as equal for read") + panic(fmt.Sprintln("complex128 map does not treat -0 and +0 as equal for read")) } m[nz] = "-0" if m[pz] != "-0" { - fmt.Println("complex128 map does not treat -0 and +0 as equal for write") + panic(fmt.Sprintln("complex128 map does not treat -0 and +0 as equal for write")) } if _, ok := m[nana]; ok { - fmt.Println("complex128 map allows NaN lookup (a)") + panic(fmt.Sprintln("complex128 map allows NaN lookup (a)")) } if _, ok := m[nanb]; ok { - fmt.Println("complex128 map allows NaN lookup (b)") + panic(fmt.Sprintln("complex128 map allows NaN lookup (b)")) } if len(m) != 3 { - fmt.Println("complex128 map should have 3 entries:", m) + panic(fmt.Sprintln("complex128 map should have 3 entries:", m)) } m[nana] = "NaN" m[nanb] = "NaN" if len(m) != 5 { - fmt.Println("complex128 map should have 5 entries:", m) + panic(fmt.Sprintln("complex128 map should have 5 entries:", m)) } } } @@ -685,7 +689,7 @@ func testnan() { } fails++ if fails == 4 { - fmt.Printf("too slow: %d inserts: %v; %d inserts: %v\n", n, t1, 2*n, t2) + panic(fmt.Sprintf("too slow: %d inserts: %v; %d inserts: %v\n", n, t1, 2*n, t2)) return } n *= 2 diff --git a/test/method.go b/test/method.go index 0c239afbd..d97bc4a7d 100644 --- a/test/method.go +++ b/test/method.go @@ -128,13 +128,13 @@ func main() { panic("fail") } - var zs struct { S } - var zps struct { *S1 } - var zi struct { I } - var zpi struct { *I1 } - var zpt struct { *T1 } - var zt struct { T } - var zv struct { Val } + var zs struct{ S } + var zps struct{ *S1 } + var zi struct{ I } + var zpi struct{ *I1 } + var zpt struct{ *T1 } + var zt struct{ T } + var zv struct{ Val } if zs.val() != 1 { println("zs.val:", zs.val()) @@ -247,4 +247,61 @@ func main() { println("zv.val():", zv.val()) panic("fail") } + + promotion() +} + +type A struct{ B } +type B struct { + C + *D +} +type C int + +func (C) f() {} // value receiver, direct field of A +func (*C) g() {} // pointer receiver + +type D int + +func (D) h() {} // value receiver, indirect field of A +func (*D) i() {} // pointer receiver + +func expectPanic() { + if r := recover(); r == nil { + panic("expected nil dereference") + } +} + +func promotion() { + var a A + // Addressable value receiver. + a.f() + a.g() + func() { + defer expectPanic() + a.h() // dynamic error: nil dereference in a.B.D->f() + }() + a.i() + + // Non-addressable value receiver. + A(a).f() + // A(a).g() // static error: cannot call pointer method on A literal.B.C + func() { + defer expectPanic() + A(a).h() // dynamic error: nil dereference in A().B.D->f() + }() + A(a).i() + + // Pointer receiver. + (&a).f() + (&a).g() + func() { + defer expectPanic() + (&a).h() // dynamic error: nil deref: nil dereference in (&a).B.D->f() + }() + (&a).i() + + c := new(C) + c.f() // makes a copy + c.g() } diff --git a/test/method4a.go b/test/method4.dir/method4a.go index d23039bfa..a7df04cec 100644 --- a/test/method4a.go +++ b/test/method4.dir/method4a.go @@ -1,11 +1,8 @@ -// skip - // 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 method expressions with arguments. -// This file is not tested by itself; it is imported by method4.go. package method4a diff --git a/test/method4.dir/prog.go b/test/method4.dir/prog.go new file mode 100644 index 000000000..77d580cff --- /dev/null +++ b/test/method4.dir/prog.go @@ -0,0 +1,104 @@ +// 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 method expressions with arguments. + +package main + +import "./method4a" + +type T1 int + +type T2 struct { + f int +} + +type I1 interface { + Sum([]int, int) int +} + +type I2 interface { + Sum(a []int, b int) int +} + +func (i T1) Sum(a []int, b int) int { + r := int(i) + b + for _, v := range a { + r += v + } + return r +} + +func (p *T2) Sum(a []int, b int) int { + r := p.f + b + for _, v := range a { + r += v + } + return r +} + +func eq(v1, v2 int) { + if v1 != v2 { + panic(0) + } +} + +func main() { + a := []int{1, 2, 3} + t1 := T1(4) + t2 := &T2{4} + + eq(t1.Sum(a, 5), 15) + eq(t2.Sum(a, 6), 16) + + eq(T1.Sum(t1, a, 7), 17) + eq((*T2).Sum(t2, a, 8), 18) + + f1 := T1.Sum + eq(f1(t1, a, 9), 19) + f2 := (*T2).Sum + eq(f2(t2, a, 10), 20) + + eq(I1.Sum(t1, a, 11), 21) + eq(I1.Sum(t2, a, 12), 22) + + f3 := I1.Sum + eq(f3(t1, a, 13), 23) + eq(f3(t2, a, 14), 24) + + eq(I2.Sum(t1, a, 15), 25) + eq(I2.Sum(t2, a, 16), 26) + + f4 := I2.Sum + eq(f4(t1, a, 17), 27) + eq(f4(t2, a, 18), 28) + + mt1 := method4a.T1(4) + mt2 := &method4a.T2{4} + + eq(mt1.Sum(a, 30), 40) + eq(mt2.Sum(a, 31), 41) + + eq(method4a.T1.Sum(mt1, a, 32), 42) + eq((*method4a.T2).Sum(mt2, a, 33), 43) + + g1 := method4a.T1.Sum + eq(g1(mt1, a, 34), 44) + g2 := (*method4a.T2).Sum + eq(g2(mt2, a, 35), 45) + + eq(method4a.I1.Sum(mt1, a, 36), 46) + eq(method4a.I1.Sum(mt2, a, 37), 47) + + g3 := method4a.I1.Sum + eq(g3(mt1, a, 38), 48) + eq(g3(mt2, a, 39), 49) + + eq(method4a.I2.Sum(mt1, a, 40), 50) + eq(method4a.I2.Sum(mt2, a, 41), 51) + + g4 := method4a.I2.Sum + eq(g4(mt1, a, 42), 52) + eq(g4(mt2, a, 43), 53) +} diff --git a/test/method4.go b/test/method4.go index 77e409b91..813892bc8 100644 --- a/test/method4.go +++ b/test/method4.go @@ -1,106 +1,8 @@ -// $G $D/method4a.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 // license that can be found in the LICENSE file. // Test method expressions with arguments. - -package main - -import "./method4a" - -type T1 int - -type T2 struct { - f int -} - -type I1 interface { - Sum([]int, int) int -} - -type I2 interface { - Sum(a []int, b int) int -} - -func (i T1) Sum(a []int, b int) int { - r := int(i) + b - for _, v := range a { - r += v - } - return r -} - -func (p *T2) Sum(a []int, b int) int { - r := p.f + b - for _, v := range a { - r += v - } - return r -} - -func eq(v1, v2 int) { - if v1 != v2 { - panic(0) - } -} - -func main() { - a := []int{1, 2, 3} - t1 := T1(4) - t2 := &T2{4} - - eq(t1.Sum(a, 5), 15) - eq(t2.Sum(a, 6), 16) - - eq(T1.Sum(t1, a, 7), 17) - eq((*T2).Sum(t2, a, 8), 18) - - f1 := T1.Sum - eq(f1(t1, a, 9), 19) - f2 := (*T2).Sum - eq(f2(t2, a, 10), 20) - - eq(I1.Sum(t1, a, 11), 21) - eq(I1.Sum(t2, a, 12), 22) - - f3 := I1.Sum - eq(f3(t1, a, 13), 23) - eq(f3(t2, a, 14), 24) - - eq(I2.Sum(t1, a, 15), 25) - eq(I2.Sum(t2, a, 16), 26) - - f4 := I2.Sum - eq(f4(t1, a, 17), 27) - eq(f4(t2, a, 18), 28) - - mt1 := method4a.T1(4) - mt2 := &method4a.T2{4} - - eq(mt1.Sum(a, 30), 40) - eq(mt2.Sum(a, 31), 41) - - eq(method4a.T1.Sum(mt1, a, 32), 42) - eq((*method4a.T2).Sum(mt2, a, 33), 43) - - g1 := method4a.T1.Sum - eq(g1(mt1, a, 34), 44) - g2 := (*method4a.T2).Sum - eq(g2(mt2, a, 35), 45) - - eq(method4a.I1.Sum(mt1, a, 36), 46) - eq(method4a.I1.Sum(mt2, a, 37), 47) - - g3 := method4a.I1.Sum - eq(g3(mt1, a, 38), 48) - eq(g3(mt2, a, 39), 49) - - eq(method4a.I2.Sum(mt1, a, 40), 50) - eq(method4a.I2.Sum(mt2, a, 41), 51) - - g4 := method4a.I2.Sum - eq(g4(mt1, a, 42), 52) - eq(g4(mt2, a, 43), 53) -} +package ignored diff --git a/test/nil.go b/test/nil.go index 9f7bcbb59..f8300bf56 100644 --- a/test/nil.go +++ b/test/nil.go @@ -115,7 +115,7 @@ func chantest() { }) shouldBlock(func() { x, ok := <-ch - println(x, ok) + println(x, ok) // unreachable }) if len(ch) != 0 { @@ -147,13 +147,13 @@ func maptest() { panic(v) } + // can delete (non-existent) entries + delete(m, 2) + // but cannot be written to shouldPanic(func() { m[2] = 3 }) - shouldPanic(func() { - delete(m, 2) - }) } // nil slice diff --git a/test/nul1.go b/test/nul1.go index 142d4deb1..20426b4fa 100644 --- a/test/nul1.go +++ b/test/nul1.go @@ -1,7 +1,4 @@ -// [ "$GORUN" == "" ] || exit 0 # Android runner gets confused by the NUL output -// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && -// errchk $G -e tmp.go -// rm -f tmp.go +// errorcheckoutput // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/range.go b/test/range.go index 68b0c9a2f..8effbe9c5 100644 --- a/test/range.go +++ b/test/range.go @@ -55,10 +55,10 @@ func testslice() { panic("fail") } if s != 15 { - println("wrong sum ranging over makeslice") + println("wrong sum ranging over makeslice", s) panic("fail") } - + x := []int{10, 20} y := []int{99} i := 1 @@ -82,7 +82,7 @@ func testslice1() { panic("fail") } if s != 10 { - println("wrong sum ranging over makeslice") + println("wrong sum ranging over makeslice", s) panic("fail") } } @@ -106,7 +106,7 @@ func testarray() { panic("fail") } if s != 15 { - println("wrong sum ranging over makearray") + println("wrong sum ranging over makearray", s) panic("fail") } } @@ -122,7 +122,7 @@ func testarray1() { panic("fail") } if s != 10 { - println("wrong sum ranging over makearray") + println("wrong sum ranging over makearray", s) panic("fail") } } @@ -155,7 +155,7 @@ func testarrayptr() { panic("fail") } if s != 15 { - println("wrong sum ranging over makearrayptr") + println("wrong sum ranging over makearrayptr", s) panic("fail") } } @@ -171,7 +171,7 @@ func testarrayptr1() { panic("fail") } if s != 10 { - println("wrong sum ranging over makearrayptr") + println("wrong sum ranging over makearrayptr", s) panic("fail") } } @@ -195,7 +195,7 @@ func teststring() { panic("fail") } if s != 'a'+'b'+'c'+'d'+'☺' { - println("wrong sum ranging over makestring") + println("wrong sum ranging over makestring", s) panic("fail") } } @@ -211,7 +211,7 @@ func teststring1() { panic("fail") } if s != 10 { - println("wrong sum ranging over makestring") + println("wrong sum ranging over makestring", s) panic("fail") } } @@ -235,7 +235,7 @@ func testmap() { panic("fail") } if s != 'a'+'b'+'c'+'d'+'☺' { - println("wrong sum ranging over makemap") + println("wrong sum ranging over makemap", s) panic("fail") } } @@ -251,7 +251,7 @@ func testmap1() { panic("fail") } if s != 10 { - println("wrong sum ranging over makemap") + println("wrong sum ranging over makemap", s) panic("fail") } } diff --git a/test/recover.go b/test/recover.go index eea655ec5..7c27d7c4d 100644 --- a/test/recover.go +++ b/test/recover.go @@ -8,15 +8,21 @@ package main -import "runtime" +import ( + "os" + "runtime" +) func main() { test1() test1WithClosures() test2() test3() - test4() - test5() + // exp/ssa/interp still has some bugs in recover(). + if os.Getenv("GOSSAINTERP") == "" { + test4() + test5() + } test6() test6WithClosures() test7() diff --git a/test/recover3.go b/test/recover3.go index 98700231e..ebfa0a307 100644 --- a/test/recover3.go +++ b/test/recover3.go @@ -71,6 +71,10 @@ func main() { inter = 1 check("type-concrete", func() { println(inter.(string)) }, "int, not string") check("type-interface", func() { println(inter.(m)) }, "missing method m") + + if didbug { + panic("recover3") + } } type m interface { diff --git a/test/rename.go b/test/rename.go index e54427455..dc4341718 100644 --- a/test/rename.go +++ b/test/rename.go @@ -8,7 +8,10 @@ package main -import "fmt" +import ( + "fmt" + "runtime" +) func main() { n := @@ -52,6 +55,7 @@ func main() { iota if n != NUM*(NUM-1)/2 { fmt.Println("BUG: wrong n", n, NUM*(NUM-1)/2) + runtime.Breakpoint() // panic is inaccessible } } diff --git a/test/reorder.go b/test/reorder.go index 007039e8a..8fd623c1c 100644 --- a/test/reorder.go +++ b/test/reorder.go @@ -42,7 +42,7 @@ func check3(x, y, z, xx, yy, zz int) { } func p1() { - x := []int{1,2,3} + x := []int{1, 2, 3} i := 0 i, x[i] = 1, 100 _ = i @@ -50,7 +50,7 @@ func p1() { } func p2() { - x := []int{1,2,3} + x := []int{1, 2, 3} i := 0 x[i], i = 100, 1 _ = i @@ -58,7 +58,7 @@ func p2() { } func p3() { - x := []int{1,2,3} + x := []int{1, 2, 3} y := x gx = x x[1], y[0] = f(0), f(1) @@ -66,7 +66,7 @@ func p3() { } func p4() { - x := []int{1,2,3} + x := []int{1, 2, 3} y := x gx = x x[1], y[0] = gx[0], gx[1] @@ -74,7 +74,7 @@ func p4() { } func p5() { - x := []int{1,2,3} + x := []int{1, 2, 3} y := x p := &x[0] q := &x[1] @@ -89,7 +89,7 @@ func p6() { px := &x py := &y *px, *py = y, x - check3(x, y, z, 2, 1, 3) + check3(x, y, z, 2, 1, 3) } func f1(x, y, z int) (xx, yy, zz int) { @@ -106,16 +106,9 @@ func p7() { } func p8() { - x := []int{1,2,3} - - defer func() { - err := recover() - if err == nil { - panic("not panicking") - } - check(x, 100, 2, 3) - }() - - i := 0 - i, x[i], x[5] = 1, 100, 500 + m := make(map[int]int) + m[0] = len(m) + if m[0] != 0 { + panic(m[0]) + } } diff --git a/test/rotate.go b/test/rotate.go new file mode 100644 index 000000000..1d7149702 --- /dev/null +++ b/test/rotate.go @@ -0,0 +1,166 @@ +// skip + +// NOTE: the actual tests to run are rotate[0123].go + +// 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. + +// Generate test of shift and rotate by constants. +// The output is compiled and run. +// +// The integer type depends on the value of mode (rotate direction, +// signedness). + +package main + +import ( + "bufio" + "flag" + "fmt" + "os" + "strings" +) + +func main() { + flag.Parse() + + b := bufio.NewWriter(os.Stdout) + defer b.Flush() + + fmt.Fprintf(b, "%s\n", prolog) + + for logBits := uint(3); logBits <= 6; logBits++ { + typ := fmt.Sprintf("int%d", 1<<logBits) + fmt.Fprint(b, strings.Replace(checkFunc, "XXX", typ, -1)) + fmt.Fprint(b, strings.Replace(checkFunc, "XXX", "u"+typ, -1)) + gentest(b, 1<<logBits, mode&1 != 0, mode&2 != 0) + } +} + +const prolog = ` + +package main + +import ( + "fmt" + "os" +) + +var ( + i8 int8 = 0x12 + i16 int16 = 0x1234 + i32 int32 = 0x12345678 + i64 int64 = 0x123456789abcdef0 + ui8 uint8 = 0x12 + ui16 uint16 = 0x1234 + ui32 uint32 = 0x12345678 + ui64 uint64 = 0x123456789abcdef0 + + ni8 = ^i8 + ni16 = ^i16 + ni32 = ^i32 + ni64 = ^i64 + nui8 = ^ui8 + nui16 = ^ui16 + nui32 = ^ui32 + nui64 = ^ui64 +) + +var nfail = 0 + +func main() { + if nfail > 0 { + fmt.Printf("BUG\n") + } +} + +` + +const checkFunc = ` +func check_XXX(desc string, have, want XXX) { + if have != want { + nfail++ + fmt.Printf("%s = %T(%#x), want %T(%#x)\n", desc, have, have, want, want) + if nfail >= 100 { + fmt.Printf("BUG: stopping after 100 failures\n") + os.Exit(0) + } + } +} +` + +var ( + uop = [2]func(x, y uint64) uint64{ + func(x, y uint64) uint64 { + return x | y + }, + func(x, y uint64) uint64 { + return x ^ y + }, + } + iop = [2]func(x, y int64) int64{ + func(x, y int64) int64 { + return x | y + }, + func(x, y int64) int64 { + return x ^ y + }, + } + cop = [2]byte{'|', '^'} +) + +func gentest(b *bufio.Writer, bits uint, unsigned, inverted bool) { + fmt.Fprintf(b, "func init() {\n") + defer fmt.Fprintf(b, "}\n") + n := 0 + + // Generate tests for left/right and right/left. + for l := uint(0); l <= bits; l++ { + for r := uint(0); r <= bits; r++ { + for o, op := range cop { + typ := fmt.Sprintf("int%d", bits) + v := fmt.Sprintf("i%d", bits) + if unsigned { + typ = "u" + typ + v = "u" + v + } + v0 := int64(0x123456789abcdef0) + if inverted { + v = "n" + v + v0 = ^v0 + } + expr1 := fmt.Sprintf("%s<<%d %c %s>>%d", v, l, op, v, r) + expr2 := fmt.Sprintf("%s>>%d %c %s<<%d", v, r, op, v, l) + + var result string + if unsigned { + v := uint64(v0) >> (64 - bits) + v = uop[o](v<<l, v>>r) + v <<= 64 - bits + v >>= 64 - bits + result = fmt.Sprintf("%#x", v) + } else { + v := int64(v0) >> (64 - bits) + v = iop[o](v<<l, v>>r) + v <<= 64 - bits + v >>= 64 - bits + result = fmt.Sprintf("%#x", v) + } + + fmt.Fprintf(b, "\tcheck_%s(%q, %s, %s(%s))\n", typ, expr1, expr1, typ, result) + fmt.Fprintf(b, "\tcheck_%s(%q, %s, %s(%s))\n", typ, expr2, expr2, typ, result) + + // Chop test into multiple functions so that there's not one + // enormous function to compile/link. + // All the functions are named init so we don't have to do + // anything special to call them. ☺ + if n++; n >= 50 { + fmt.Fprintf(b, "}\n") + fmt.Fprintf(b, "func init() {\n") + n = 0 + } + } + } + } +} diff --git a/test/rotate0.go b/test/rotate0.go new file mode 100644 index 000000000..400b225cf --- /dev/null +++ b/test/rotate0.go @@ -0,0 +1,12 @@ +// runoutput ./rotate.go + +// 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. + +// Generate test of bit rotations. +// The output is compiled and run. + +package main + +const mode = 0 diff --git a/test/rotate1.go b/test/rotate1.go new file mode 100644 index 000000000..98b0b1c84 --- /dev/null +++ b/test/rotate1.go @@ -0,0 +1,12 @@ +// runoutput ./rotate.go + +// 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. + +// Generate test of bit rotations. +// The output is compiled and run. + +package main + +const mode = 1 diff --git a/test/rotate2.go b/test/rotate2.go new file mode 100644 index 000000000..c50f8ce73 --- /dev/null +++ b/test/rotate2.go @@ -0,0 +1,12 @@ +// runoutput ./rotate.go + +// 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. + +// Generate test of bit rotations. +// The output is compiled and run. + +package main + +const mode = 2 diff --git a/test/rotate3.go b/test/rotate3.go new file mode 100644 index 000000000..73d47d852 --- /dev/null +++ b/test/rotate3.go @@ -0,0 +1,12 @@ +// runoutput ./rotate.go + +// 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. + +// Generate test of bit rotations. +// The output is compiled and run. + +package main + +const mode = 3 @@ -54,6 +54,8 @@ true >pass.out >times.out exclude=false # exclude nothing golden=golden.out +rm -f tmp.go # generated by some tests, left behind if interrupted + filterout() { grep '^'"$2"'$' $1 >/dev/null } @@ -100,7 +102,7 @@ do echo $i >>pass.out fi echo $(awk 'NR==1{print $2}' "$TMP2FILE") $D/$F >>times.out - rm -f $F.$A $A.out + rm -f $F.$A $A.out tmp.go ) done done | # clean up some stack noise egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' | diff --git a/test/run.go b/test/run.go index ac6e3c0e2..5e167d6b0 100644 --- a/test/run.go +++ b/test/run.go @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file. // Run runs tests in the test directory. -// +// // TODO(bradfitz): docs of some sort, once we figure out how we're changing // headers of files package main @@ -20,6 +20,7 @@ import ( "log" "os" "os/exec" + "path" "path/filepath" "regexp" "runtime" @@ -29,10 +30,11 @@ import ( ) var ( - verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.") - numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run") - summary = flag.Bool("summary", false, "show summary of results") - showSkips = flag.Bool("show_skips", false, "show skipped tests") + verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.") + numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run") + summary = flag.Bool("summary", false, "show summary of results") + showSkips = flag.Bool("show_skips", false, "show skipped tests") + runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run") ) var ( @@ -52,6 +54,10 @@ var ( // toRun is the channel of tests to run. // It is nil until the first test is started. toRun chan *test + + // rungatec controls the max number of runoutput tests + // executed in parallel as they can each consume a lot of memory. + rungatec chan bool ) // maxTests is an upper bound on the total number of tests. @@ -67,6 +73,7 @@ func main() { } ratec = make(chan bool, *numParallel) + rungatec = make(chan bool, *runoutputLimit) var err error letter, err = build.ArchChar(build.Default.GOARCH) check(err) @@ -77,16 +84,23 @@ func main() { if flag.NArg() > 0 { for _, arg := range flag.Args() { if arg == "-" || arg == "--" { - // Permit running either: + // Permit running: // $ go run run.go - env.go // $ go run run.go -- env.go + // $ go run run.go - ./fixedbugs + // $ go run run.go -- ./fixedbugs continue } - if !strings.HasSuffix(arg, ".go") { - log.Fatalf("can't yet deal with non-go file %q", arg) + if fi, err := os.Stat(arg); err == nil && fi.IsDir() { + for _, baseGoFile := range goFiles(arg) { + tests = append(tests, startTest(arg, baseGoFile)) + } + } else if strings.HasSuffix(arg, ".go") { + dir, file := filepath.Split(arg) + tests = append(tests, startTest(dir, file)) + } else { + log.Fatalf("can't yet deal with non-directory and non-go file %q", arg) } - dir, file := filepath.Split(arg) - tests = append(tests, startTest(dir, file)) } } else { for _, dir := range dirs { @@ -102,15 +116,17 @@ func main() { <-test.donec _, isSkip := test.err.(skipError) errStr := "pass" - if isSkip { - errStr = "skip" - } if test.err != nil { errStr = test.err.Error() if !isSkip { failed = true } } + if isSkip && !skipOkay[path.Join(test.dir, test.gofile)] { + errStr = "unexpected skip for " + path.Join(test.dir, test.gofile) + ": " + errStr + isSkip = false + failed = true + } resCount[errStr]++ if isSkip && !*verbose && !*showSkips { continue @@ -118,7 +134,7 @@ func main() { if !*verbose && test.err == nil { continue } - fmt.Printf("%-10s %-20s: %s\n", test.action, test.goFileName(), errStr) + fmt.Printf("%-20s %-20s: %s\n", test.action, test.goFileName(), errStr) } if *summary { @@ -155,6 +171,26 @@ func goFiles(dir string) []string { return names } +type runCmd func(...string) ([]byte, error) + +func compileFile(runcmd runCmd, longname string) (out []byte, err error) { + return runcmd("go", "tool", gc, "-e", longname) +} + +func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) { + cmd := []string{"go", "tool", gc, "-e", "-D", ".", "-I", "."} + for _, name := range names { + cmd = append(cmd, filepath.Join(dir, name)) + } + return runcmd(cmd...) +} + +func linkFile(runcmd runCmd, goname string) (err error) { + pfile := strings.Replace(goname, ".go", "."+letter, -1) + _, err = runcmd("go", "tool", ld, "-o", "a.exe", "-L", ".", pfile) + return +} + // skipError describes why a test was skipped. type skipError string @@ -172,13 +208,13 @@ type test struct { donec chan bool // closed when done src string - action string // "compile", "build", "run", "errorcheck", "skip" + action string // "compile", "build", etc. tempDir string err error } -// startTest +// startTest func startTest(dir, gofile string) *test { t := &test{ dir: dir, @@ -216,6 +252,97 @@ func (t *test) goFileName() string { return filepath.Join(t.dir, t.gofile) } +func (t *test) goDirName() string { + return filepath.Join(t.dir, strings.Replace(t.gofile, ".go", ".dir", -1)) +} + +func goDirFiles(longdir string) (filter []os.FileInfo, err error) { + files, dirErr := ioutil.ReadDir(longdir) + if dirErr != nil { + return nil, dirErr + } + for _, gofile := range files { + if filepath.Ext(gofile.Name()) == ".go" { + filter = append(filter, gofile) + } + } + return +} + +var packageRE = regexp.MustCompile(`(?m)^package (\w+)`) + +func goDirPackages(longdir string) ([][]string, error) { + files, err := goDirFiles(longdir) + if err != nil { + return nil, err + } + var pkgs [][]string + m := make(map[string]int) + for _, file := range files { + name := file.Name() + data, err := ioutil.ReadFile(filepath.Join(longdir, name)) + if err != nil { + return nil, err + } + pkgname := packageRE.FindStringSubmatch(string(data)) + if pkgname == nil { + return nil, fmt.Errorf("cannot find package name in %s", name) + } + i, ok := m[pkgname[1]] + if !ok { + i = len(pkgs) + pkgs = append(pkgs, nil) + m[pkgname[1]] = i + } + pkgs[i] = append(pkgs[i], name) + } + return pkgs, nil +} + +// shouldTest looks for build tags in a source file and returns +// whether the file should be used according to the tags. +func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) { + if idx := strings.Index(src, "\npackage"); idx >= 0 { + src = src[:idx] + } + notgoos := "!" + goos + notgoarch := "!" + goarch + for _, line := range strings.Split(src, "\n") { + line = strings.TrimSpace(line) + if strings.HasPrefix(line, "//") { + line = line[2:] + } else { + continue + } + line = strings.TrimSpace(line) + if len(line) == 0 || line[0] != '+' { + continue + } + words := strings.Fields(line) + if words[0] == "+build" { + for _, word := range words { + switch word { + case goos, goarch: + return true, "" + case notgoos, notgoarch: + continue + default: + if word[0] == '!' { + // NOT something-else + return true, "" + } + } + } + // no matching tag found. + return false, line + } + } + // no build tags. + return true, "" +} + +func init() { checkShouldTest() } + // run runs a test. func (t *test) run() { defer close(t.donec) @@ -235,12 +362,24 @@ func (t *test) run() { t.err = errors.New("double newline not found") return } + if ok, why := shouldTest(t.src, runtime.GOOS, runtime.GOARCH); !ok { + t.action = "skip" + if *showSkips { + fmt.Printf("%-20s %-20s: %s\n", t.action, t.goFileName(), why) + } + return + } action := t.src[:pos] + if nl := strings.Index(action, "\n"); nl >= 0 && strings.Contains(action[:nl], "+build") { + // skip first line + action = action[nl+1:] + } if strings.HasPrefix(action, "//") { action = action[2:] } - var args []string + var args, flags []string + wantError := false f := strings.Fields(action) if len(f) > 0 { action = f[0] @@ -248,11 +387,25 @@ func (t *test) run() { } switch action { + case "rundircmpout": + action = "rundir" + t.action = "rundir" case "cmpout": action = "run" // the run case already looks for <dir>/<test>.out files fallthrough - case "compile", "build", "run", "errorcheck": + case "compile", "compiledir", "build", "run", "runoutput", "rundir": t.action = action + case "errorcheck", "errorcheckdir", "errorcheckoutput": + t.action = action + wantError = true + for len(args) > 0 && strings.HasPrefix(args[0], "-") { + if args[0] == "-0" { + wantError = false + } else { + flags = append(flags, args[0]) + } + args = args[1:] + } case "skip": t.action = "skip" return @@ -280,8 +433,12 @@ func (t *test) run() { cmd.Stderr = &buf if useTmp { cmd.Dir = t.tempDir + cmd.Env = envForDir(cmd.Dir) } err := cmd.Run() + if err != nil { + err = fmt.Errorf("%s\n%s", err, buf.Bytes()) + } return buf.Bytes(), err } @@ -291,31 +448,175 @@ func (t *test) run() { t.err = fmt.Errorf("unimplemented action %q", action) case "errorcheck": - out, _ := runcmd("go", "tool", gc, "-e", "-o", "a."+letter, long) + cmdline := []string{"go", "tool", gc, "-e", "-o", "a." + letter} + cmdline = append(cmdline, flags...) + cmdline = append(cmdline, long) + out, err := runcmd(cmdline...) + if wantError { + if err == nil { + t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) + return + } + } else { + if err != nil { + t.err = err + return + } + } t.err = t.errorCheck(string(out), long, t.gofile) return case "compile": - out, err := runcmd("go", "tool", gc, "-e", "-o", "a."+letter, long) + _, t.err = compileFile(runcmd, long) + + case "compiledir": + // Compile all files in the directory in lexicographic order. + longdir := filepath.Join(cwd, t.goDirName()) + pkgs, err := goDirPackages(longdir) if err != nil { - t.err = fmt.Errorf("%s\n%s", err, out) + t.err = err + return + } + for _, gofiles := range pkgs { + _, t.err = compileInDir(runcmd, longdir, gofiles...) + if t.err != nil { + return + } + } + + case "errorcheckdir": + // errorcheck all files in lexicographic order + // useful for finding importing errors + longdir := filepath.Join(cwd, t.goDirName()) + pkgs, err := goDirPackages(longdir) + if err != nil { + t.err = err + return + } + for i, gofiles := range pkgs { + out, err := compileInDir(runcmd, longdir, gofiles...) + if i == len(pkgs)-1 { + if wantError && err == nil { + t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) + return + } else if !wantError && err != nil { + t.err = err + return + } + } else if err != nil { + t.err = err + return + } + var fullshort []string + for _, name := range gofiles { + fullshort = append(fullshort, filepath.Join(longdir, name), name) + } + t.err = t.errorCheck(string(out), fullshort...) + if t.err != nil { + break + } + } + + case "rundir": + // Compile all files in the directory in lexicographic order. + // then link as if the last file is the main package and run it + longdir := filepath.Join(cwd, t.goDirName()) + pkgs, err := goDirPackages(longdir) + if err != nil { + t.err = err + return + } + for i, gofiles := range pkgs { + _, err := compileInDir(runcmd, longdir, gofiles...) + if err != nil { + t.err = err + return + } + if i == len(pkgs)-1 { + err = linkFile(runcmd, gofiles[0]) + if err != nil { + t.err = err + return + } + out, err := runcmd(append([]string{filepath.Join(t.tempDir, "a.exe")}, args...)...) + if err != nil { + t.err = err + return + } + if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { + t.err = fmt.Errorf("incorrect output\n%s", out) + } + } } case "build": - out, err := runcmd("go", "build", "-o", "a.exe", long) + _, err := runcmd("go", "build", "-o", "a.exe", long) if err != nil { - t.err = fmt.Errorf("%s\n%s", err, out) + t.err = err } case "run": useTmp = false out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) if err != nil { - t.err = fmt.Errorf("%s\n%s", err, out) + t.err = err + } + if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { + t.err = fmt.Errorf("incorrect output\n%s", out) + } + + case "runoutput": + rungatec <- true + defer func() { + <-rungatec + }() + useTmp = false + out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) + if err != nil { + t.err = err + } + tfile := filepath.Join(t.tempDir, "tmp__.go") + if err := ioutil.WriteFile(tfile, out, 0666); err != nil { + t.err = fmt.Errorf("write tempfile:%s", err) + return + } + out, err = runcmd("go", "run", tfile) + if err != nil { + t.err = err } if string(out) != t.expectedOutput() { t.err = fmt.Errorf("incorrect output\n%s", out) } + + case "errorcheckoutput": + useTmp = false + out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) + if err != nil { + t.err = err + } + tfile := filepath.Join(t.tempDir, "tmp__.go") + err = ioutil.WriteFile(tfile, out, 0666) + if err != nil { + t.err = fmt.Errorf("write tempfile:%s", err) + return + } + cmdline := []string{"go", "tool", gc, "-e", "-o", "a." + letter} + cmdline = append(cmdline, flags...) + cmdline = append(cmdline, tfile) + out, err = runcmd(cmdline...) + if wantError { + if err == nil { + t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out) + return + } + } else { + if err != nil { + t.err = err + return + } + } + t.err = t.errorCheck(string(out), tfile, "tmp__.go") + return } } @@ -337,7 +638,7 @@ func (t *test) expectedOutput() string { return string(b) } -func (t *test) errorCheck(outStr string, full, short string) (err error) { +func (t *test) errorCheck(outStr string, fullshort ...string) (err error) { defer func() { if *verbose && err != nil { log.Printf("%s gc output:\n%s", t, outStr) @@ -349,19 +650,33 @@ func (t *test) errorCheck(outStr string, full, short string) (err error) { // 6g error messages continue onto additional lines with leading tabs. // Split the output at the beginning of each line that doesn't begin with a tab. for _, line := range strings.Split(outStr, "\n") { + if strings.HasSuffix(line, "\r") { // remove '\r', output by compiler on windows + line = line[:len(line)-1] + } if strings.HasPrefix(line, "\t") { out[len(out)-1] += "\n" + line - } else { + } else if strings.HasPrefix(line, "go tool") { + continue + } else if strings.TrimSpace(line) != "" { out = append(out, line) } } // Cut directory name. for i := range out { - out[i] = strings.Replace(out[i], full, short, -1) + for j := 0; j < len(fullshort); j += 2 { + full, short := fullshort[j], fullshort[j+1] + out[i] = strings.Replace(out[i], full, short, -1) + } + } + + var want []wantedError + for j := 0; j < len(fullshort); j += 2 { + full, short := fullshort[j], fullshort[j+1] + want = append(want, t.wantedErrors(full, short)...) } - for _, we := range t.wantedErrors() { + for _, we := range want { var errmsgs []string errmsgs, out = partitionStrings(we.filterRe, out) if len(errmsgs) == 0 { @@ -369,6 +684,7 @@ func (t *test) errorCheck(outStr string, full, short string) (err error) { continue } matched := false + n := len(out) for _, errmsg := range errmsgs { if we.re.MatchString(errmsg) { matched = true @@ -377,11 +693,18 @@ func (t *test) errorCheck(outStr string, full, short string) (err error) { } } if !matched { - errs = append(errs, fmt.Errorf("%s:%d: no match for %q in%s", we.file, we.lineNum, we.reStr, strings.Join(out, "\n"))) + errs = append(errs, fmt.Errorf("%s:%d: no match for %#q in:\n\t%s", we.file, we.lineNum, we.reStr, strings.Join(out[n:], "\n\t"))) continue } } + if len(out) > 0 { + errs = append(errs, fmt.Errorf("Unmatched Errors:")) + for _, errLine := range out { + errs = append(errs, fmt.Errorf("%s", errLine)) + } + } + if len(errs) == 0 { return nil } @@ -422,8 +745,9 @@ var ( lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`) ) -func (t *test) wantedErrors() (errs []wantedError) { - for i, line := range strings.Split(t.src, "\n") { +func (t *test) wantedErrors(file, short string) (errs []wantedError) { + src, _ := ioutil.ReadFile(file) + for i, line := range strings.Split(string(src), "\n") { lineNum := i + 1 if strings.Contains(line, "////") { // double comment disables ERROR @@ -436,7 +760,7 @@ func (t *test) wantedErrors() (errs []wantedError) { all := m[1] mm := errQuotesRx.FindAllStringSubmatch(all, -1) if mm == nil { - log.Fatalf("invalid errchk line in %s: %s", t.goFileName(), line) + log.Fatalf("%s:%d: invalid errchk line: %s", t.goFileName(), lineNum, line) } for _, m := range mm { rx := lineRx.ReplaceAllStringFunc(m[1], func(m string) string { @@ -448,18 +772,77 @@ func (t *test) wantedErrors() (errs []wantedError) { delta, _ := strconv.Atoi(m[5:]) n -= delta } - return fmt.Sprintf("%s:%d", t.gofile, n) + return fmt.Sprintf("%s:%d", short, n) }) - filterPattern := fmt.Sprintf(`^(\w+/)?%s:%d[:[]`, t.gofile, lineNum) + re, err := regexp.Compile(rx) + if err != nil { + log.Fatalf("%s:%d: invalid regexp in ERROR line: %v", t.goFileName(), lineNum, err) + } + filterPattern := fmt.Sprintf(`^(\w+/)?%s:%d[:[]`, regexp.QuoteMeta(short), lineNum) errs = append(errs, wantedError{ reStr: rx, - re: regexp.MustCompile(rx), + re: re, filterRe: regexp.MustCompile(filterPattern), lineNum: lineNum, - file: t.gofile, + file: short, }) } } return } + +var skipOkay = map[string]bool{ + "linkx.go": true, // like "run" but wants linker flags + "sinit.go": true, + "fixedbugs/bug248.go": true, // combines errorcheckdir and rundir in the same dir. + "fixedbugs/bug302.go": true, // tests both .$O and .a imports. + "fixedbugs/bug345.go": true, // needs the appropriate flags in gc invocation. + "fixedbugs/bug369.go": true, // needs compiler flags. + "fixedbugs/bug429.go": true, // like "run" but program should fail + "bugs/bug395.go": true, +} + +// defaultRunOutputLimit returns the number of runoutput tests that +// can be executed in parallel. +func defaultRunOutputLimit() int { + const maxArmCPU = 2 + + cpu := runtime.NumCPU() + if runtime.GOARCH == "arm" && cpu > maxArmCPU { + cpu = maxArmCPU + } + return cpu +} + +// checkShouldTest runs canity checks on the shouldTest function. +func checkShouldTest() { + assert := func(ok bool, _ string) { + if !ok { + panic("fail") + } + } + assertNot := func(ok bool, _ string) { assert(!ok, "") } + assert(shouldTest("// +build linux", "linux", "arm")) + assert(shouldTest("// +build !windows", "linux", "arm")) + assertNot(shouldTest("// +build !windows", "windows", "amd64")) + assertNot(shouldTest("// +build arm 386", "linux", "amd64")) + assert(shouldTest("// This is a test.", "os", "arch")) +} + +// envForDir returns a copy of the environment +// suitable for running in the given directory. +// The environment is the current process's environment +// but with an updated $PWD, so that an os.Getwd in the +// child will be faster. +func envForDir(dir string) []string { + env := os.Environ() + for i, kv := range env { + if strings.HasPrefix(kv, "PWD=") { + env[i] = "PWD=" + dir + return env + } + } + env = append(env, "PWD="+dir) + return env +} diff --git a/test/safe/nousesafe.go b/test/safe/nousesafe.go index f61e7fe4f..fcd25af31 100644 --- a/test/safe/nousesafe.go +++ b/test/safe/nousesafe.go @@ -1,4 +1,4 @@ -// $G $D/pkg.go && pack grc pkg.a pkg.$A 2> /dev/null && rm pkg.$A && errchk $G -I. -u $D/main.go +// $G $D/pkg.go && pack grc pkg.a pkg.$A 2> /dev/null && rm pkg.$A && errchk $G -I . -u $D/main.go // rm -f pkg.a // Copyright 2012 The Go Authors. All rights reserved. diff --git a/test/safe/usesafe.go b/test/safe/usesafe.go index 07c13c1c3..5d0829e29 100644 --- a/test/safe/usesafe.go +++ b/test/safe/usesafe.go @@ -1,4 +1,4 @@ -// $G $D/pkg.go && pack grcS pkg.a pkg.$A 2> /dev/null && rm pkg.$A && $G -I. -u $D/main.go +// $G $D/pkg.go && pack grcS pkg.a pkg.$A 2> /dev/null && rm pkg.$A && $G -I . -u $D/main.go // rm -f pkg.a // Copyright 2012 The Go Authors. All rights reserved. diff --git a/test/shift1.go b/test/shift1.go index b33d22ff8..f1ec0bf58 100644 --- a/test/shift1.go +++ b/test/shift1.go @@ -36,3 +36,10 @@ var ( b2 = 1.0 << c // ERROR "overflow" d2 = f(1.0 << c) // ERROR "overflow" ) + +var ( + // issues 4882, 4936. + a3 = 1.0<<s + 0 // ERROR "invalid operation|shift of non-integer operand" + // issue 4937 + b3 = 1<<s + 1 + 1.0 // ERROR "invalid operation|shift of non-integer operand" +) diff --git a/test/sigchld.go b/test/sigchld.go index 25625a6f4..a60d28dea 100644 --- a/test/sigchld.go +++ b/test/sigchld.go @@ -1,5 +1,5 @@ -// [ "$GOOS" == windows ] || -// ($G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out) +// +build !windows +// cmpout // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/sinit.go b/test/sinit.go index 1bc281037..5e50e1100 100644 --- a/test/sinit.go +++ b/test/sinit.go @@ -1,5 +1,8 @@ // $G -S $D/$F.go | egrep initdone >/dev/null && echo BUG sinit || true +// 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. @@ -256,3 +259,13 @@ var copy_pt0a = pt0a var copy_pt0b = pt0b var copy_pt1 = pt1 var copy_pt1a = pt1a + +var _ interface{} = 1 + +type T1 int + +func (t *T1) M() {} + +type Mer interface { M() } + +var _ Mer = (*T1)(nil) diff --git a/test/string_lit.go b/test/string_lit.go index 956330038..fea6f553d 100644 --- a/test/string_lit.go +++ b/test/string_lit.go @@ -33,6 +33,7 @@ func assert(a, b, c string) { print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n") } } + panic("string_lit") } } @@ -93,7 +94,7 @@ func main() { "backslashes 2 (backquote)") assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)") - // test large runes. perhaps not the most logical place for this test. + // test large and surrogate-half runes. perhaps not the most logical place for these tests. var r int32 r = 0x10ffff // largest rune value s = string(r) @@ -101,6 +102,28 @@ func main() { r = 0x10ffff + 1 s = string(r) assert(s, "\xef\xbf\xbd", "too-large rune") + r = 0xD800 + s = string(r) + assert(s, "\xef\xbf\xbd", "surrogate rune min") + r = 0xDFFF + s = string(r) + assert(s, "\xef\xbf\xbd", "surrogate rune max") + r = -1 + s = string(r) + assert(s, "\xef\xbf\xbd", "negative rune") + + // the large rune tests again, this time using constants instead of a variable. + // these conversions will be done at compile time. + s = string(0x10ffff) // largest rune value + assert(s, "\xf4\x8f\xbf\xbf", "largest rune constant") + s = string(0x10ffff + 1) + assert(s, "\xef\xbf\xbd", "too-large rune constant") + s = string(0xD800) + assert(s, "\xef\xbf\xbd", "surrogate rune min constant") + s = string(0xDFFF) + assert(s, "\xef\xbf\xbd", "surrogate rune max constant") + s = string(-1) + assert(s, "\xef\xbf\xbd", "negative rune") assert(string(gr1), gx1, "global ->[]rune") assert(string(gr2), gx2fix, "global invalid ->[]rune") diff --git a/test/stringrange.go b/test/stringrange.go index daaba91c6..99e5edb5a 100644 --- a/test/stringrange.go +++ b/test/stringrange.go @@ -57,6 +57,13 @@ func main() { ok = false } + for _, c := range "a\xed\xa0\x80a" { + if c != 'a' && c != utf8.RuneError { + fmt.Printf("surrogate UTF-8 does not error: %U\n", c) + ok = false + } + } + if !ok { fmt.Println("BUG: stringrange") os.Exit(1) diff --git a/test/switch.go b/test/switch.go index 09bf4341a..bcbde68e4 100644 --- a/test/switch.go +++ b/test/switch.go @@ -284,12 +284,129 @@ func main() { default: } + // switch on interface. + switch i := interface{}("hello"); i { + case 42: + assert(false, `i should be "hello"`) + case "hello": + assert(true, "hello") + default: + assert(false, `i should be "hello"`) + } + + // switch on implicit bool converted to interface + // was broken: see issue 3980 + switch i := interface{}(true); { + case i: + assert(true, "true") + case false: + assert(false, "i should be true") + default: + assert(false, "i should be true") + } + + // switch on interface with constant cases differing by type. + // was rejected by compiler: see issue 4781 + type T int + type B bool + type F float64 + type S string + switch i := interface{}(float64(1.0)); i { + case nil: + assert(false, "i should be float64(1.0)") + case (*int)(nil): + assert(false, "i should be float64(1.0)") + case 1: + assert(false, "i should be float64(1.0)") + case T(1): + assert(false, "i should be float64(1.0)") + case F(1.0): + assert(false, "i should be float64(1.0)") + case 1.0: + assert(true, "true") + case "hello": + assert(false, "i should be float64(1.0)") + case S("hello"): + assert(false, "i should be float64(1.0)") + case true, B(false): + assert(false, "i should be float64(1.0)") + case false, B(true): + assert(false, "i should be float64(1.0)") + } + + // switch on array. + switch ar := [3]int{1, 2, 3}; ar { + case [3]int{1, 2, 3}: + assert(true, "[1 2 3]") + case [3]int{4, 5, 6}: + assert(false, "ar should be [1 2 3]") + default: + assert(false, "ar should be [1 2 3]") + } + + // switch on channel + switch c1, c2 := make(chan int), make(chan int); c1 { + case nil: + assert(false, "c1 did not match itself") + case c2: + assert(false, "c1 did not match itself") + case c1: + assert(true, "chan") + default: + assert(false, "c1 did not match itself") + } + + // empty switch + switch { + } + + // empty switch with default case. + fired = false + switch { + default: + fired = true + } + assert(fired, "fail") + + // Default and fallthrough. + count = 0 + switch { + default: + count++ + fallthrough + case false: + count++ + } + assert(count == 2, "fail") + + // fallthrough to default, which is not at end. + count = 0 + switch i5 { + case 5: + count++ + fallthrough + default: + count++ + case 6: + count++ + } + assert(count == 2, "fail") + + // fallthrough in final case. + count = 0 + switch i5 { + case 5: + count++ + fallthrough + } + assert(count == 1, "fail") + i := 0 switch x := 5; { - case i < x: - os.Exit(0) - case i == x: - case i > x: - os.Exit(1) + case i < x: + os.Exit(0) + case i == x: + case i > x: + os.Exit(1) } } diff --git a/test/switch3.go b/test/switch3.go index dcb6fff20..28705e464 100644 --- a/test/switch3.go +++ b/test/switch3.go @@ -45,6 +45,17 @@ func bad() { case f1: // ERROR "can only compare func f to nil|func can only be compared to nil" default: } + + var ar, ar1 [4]func() + switch ar { // ERROR "cannot switch on" + case ar1: + default: + } + + var st, st1 struct{ f func() } + switch st { // ERROR "cannot switch on" + case st1: + } } func good() { diff --git a/test/syntax/composite.go b/test/syntax/composite.go new file mode 100644 index 000000000..656533493 --- /dev/null +++ b/test/syntax/composite.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 + +var a = []int{ + 3 // ERROR "need trailing comma before newline in composite literal" +} diff --git a/test/testlib b/test/testlib index 3858431a7..de138b1d1 100644 --- a/test/testlib +++ b/test/testlib @@ -5,14 +5,104 @@ # These function names are also known to # (and are the plan for transitioning to) run.go. +# helper (not known to run.go) +# group file list by packages and return list of packages +# each package is a comma-separated list of go files. +pkgs() { + pkglist=$(grep -h '^package ' $* | awk '{print $2}' | sort -u) + for p in $pkglist + do + echo $(grep -l "^package $p\$" $*) | tr ' ' , + done | sort +} + +# +build aborts execution if the supplied tags don't match, +# i.e. none of the tags (x or !x) matches GOARCH or GOOS. ++build() { + if (( $# == 0 )); then + return + fi + for tag; do + case $tag in + $GOARCH|$GOOS) + #echo >&2 "match $tag in $1" + return # don't exclude. + ;; + '!'$GOARCH|'!'$GOOS) + ;; + '!'*) + # not x where x is neither GOOS nor GOARCH. + #echo >&2 "match $tag in $1" + return # don't exclude + ;; + esac + done + # no match. + exit 0 +} + compile() { $G $D/$F.go } +compiledir() { + for pkg in $(pkgs $D/$F.dir/*.go) + do + $G -I . $(echo $pkg | tr , ' ') || return 1 + done +} + +errorcheckdir() { + lastzero="" + if [ "$1" = "-0" ]; then + lastzero="-0" + fi + pkgs=$(pkgs $D/$F.dir/*.go) + for pkg in $pkgs.last + do + zero="-0" + case $pkg in + *.last) + pkg=$(echo $pkg |sed 's/\.last$//') + zero=$lastzero + esac + errchk $zero $G -D . -I . -e $(echo $pkg | tr , ' ') + done +} + +rundir() { + lastfile="" + for pkg in $(pkgs $D/$F.dir/*.go) + do + name=$(echo $pkg | sed 's/\.go.*//; s/.*\///') + $G -D . -I . -e $(echo $pkg | tr , ' ') || return 1 + lastfile=$name + done + $L -o $A.out -L . $lastfile.$A + ./$A.out +} + +rundircmpout() { + lastfile="" + for pkg in $(pkgs $D/$F.dir/*.go) + do + name=$(echo $pkg | sed 's/\.go.*//; s/.*\///') + $G -D . -I . -e $(echo $pkg | tr , ' ') || return 1 + lastfile=$name + done + $L -o $A.out -L . $lastfile.$A + ./$A.out 2>&1 | cmp - $D/$F.out +} + build() { $G $D/$F.go && $L $F.$A } +runoutput() { + go run "$D/$F.go" "$@" > tmp.go + go run tmp.go +} + run() { gofiles="" ingo=true @@ -36,7 +126,22 @@ cmpout() { } errorcheck() { - errchk $G -e $D/$F.go + zero="" + if [ "$1" = "-0" ]; then + zero="-0" + shift + fi + errchk $zero $G -e $* $D/$F.go +} + +errorcheckoutput() { + zero="" + if [ "$1" = "-0" ]; then + zero="-0" + shift + fi + go run "$D/$F.go" "$@" > tmp.go + errchk $zero $G -e tmp.go } skip() { diff --git a/test/torture.go b/test/torture.go new file mode 100644 index 000000000..bbf6d347d --- /dev/null +++ b/test/torture.go @@ -0,0 +1,339 @@ +// 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. + +// Various tests for expressions with high complexity. + +package main + +// Concatenate 16 4-bit integers into a 64-bit number. +func concat(s *[16]byte) uint64 { + r := (((((((((((((((uint64(s[0])<<4| + uint64(s[1]))<<4| + uint64(s[2]))<<4| + uint64(s[3]))<<4| + uint64(s[4]))<<4| + uint64(s[5]))<<4| + uint64(s[6]))<<4| + uint64(s[7]))<<4| + uint64(s[8]))<<4| + uint64(s[9]))<<4| + uint64(s[10]))<<4| + uint64(s[11]))<<4| + uint64(s[12]))<<4| + uint64(s[13]))<<4| + uint64(s[14]))<<4 | + uint64(s[15])) + return r +} + +// Compute the determinant of a 4x4-matrix by the sum +// over all index permutations. +func determinant(m [4][4]float64) float64 { + return m[0][0]*m[1][1]*m[2][2]*m[3][3] - + m[0][0]*m[1][1]*m[2][3]*m[3][2] - + m[0][0]*m[1][2]*m[2][1]*m[3][3] + + m[0][0]*m[1][2]*m[2][3]*m[3][1] + + m[0][0]*m[1][3]*m[2][1]*m[3][2] - + m[0][0]*m[1][3]*m[2][2]*m[3][1] - + m[0][1]*m[1][0]*m[2][2]*m[3][3] + + m[0][1]*m[1][0]*m[2][3]*m[3][2] + + m[0][1]*m[1][2]*m[2][0]*m[3][3] - + m[0][1]*m[1][2]*m[2][3]*m[3][0] - + m[0][1]*m[1][3]*m[2][0]*m[3][2] + + m[0][1]*m[1][3]*m[2][2]*m[3][0] + + m[0][2]*m[1][0]*m[2][1]*m[3][3] - + m[0][2]*m[1][0]*m[2][3]*m[3][1] - + m[0][2]*m[1][1]*m[2][0]*m[3][3] + + m[0][2]*m[1][1]*m[2][3]*m[3][0] + + m[0][2]*m[1][3]*m[2][0]*m[3][1] - + m[0][2]*m[1][3]*m[2][1]*m[3][0] - + m[0][3]*m[1][0]*m[2][1]*m[3][2] + + m[0][3]*m[1][0]*m[2][2]*m[3][1] + + m[0][3]*m[1][1]*m[2][0]*m[3][2] - + m[0][3]*m[1][1]*m[2][2]*m[3][0] - + m[0][3]*m[1][2]*m[2][0]*m[3][1] + + m[0][3]*m[1][2]*m[2][1]*m[3][0] +} + +// Compute the determinant of a 4x4-matrix by the sum +// over all index permutations. +func determinantInt(m [4][4]int) int { + return m[0][0]*m[1][1]*m[2][2]*m[3][3] - + m[0][0]*m[1][1]*m[2][3]*m[3][2] - + m[0][0]*m[1][2]*m[2][1]*m[3][3] + + m[0][0]*m[1][2]*m[2][3]*m[3][1] + + m[0][0]*m[1][3]*m[2][1]*m[3][2] - + m[0][0]*m[1][3]*m[2][2]*m[3][1] - + m[0][1]*m[1][0]*m[2][2]*m[3][3] + + m[0][1]*m[1][0]*m[2][3]*m[3][2] + + m[0][1]*m[1][2]*m[2][0]*m[3][3] - + m[0][1]*m[1][2]*m[2][3]*m[3][0] - + m[0][1]*m[1][3]*m[2][0]*m[3][2] + + m[0][1]*m[1][3]*m[2][2]*m[3][0] + + m[0][2]*m[1][0]*m[2][1]*m[3][3] - + m[0][2]*m[1][0]*m[2][3]*m[3][1] - + m[0][2]*m[1][1]*m[2][0]*m[3][3] + + m[0][2]*m[1][1]*m[2][3]*m[3][0] + + m[0][2]*m[1][3]*m[2][0]*m[3][1] - + m[0][2]*m[1][3]*m[2][1]*m[3][0] - + m[0][3]*m[1][0]*m[2][1]*m[3][2] + + m[0][3]*m[1][0]*m[2][2]*m[3][1] + + m[0][3]*m[1][1]*m[2][0]*m[3][2] - + m[0][3]*m[1][1]*m[2][2]*m[3][0] - + m[0][3]*m[1][2]*m[2][0]*m[3][1] + + m[0][3]*m[1][2]*m[2][1]*m[3][0] +} + +// Compute the determinant of a 4x4-matrix by the sum +// over all index permutations. +func determinantByte(m [4][4]byte) byte { + return m[0][0]*m[1][1]*m[2][2]*m[3][3] - + m[0][0]*m[1][1]*m[2][3]*m[3][2] - + m[0][0]*m[1][2]*m[2][1]*m[3][3] + + m[0][0]*m[1][2]*m[2][3]*m[3][1] + + m[0][0]*m[1][3]*m[2][1]*m[3][2] - + m[0][0]*m[1][3]*m[2][2]*m[3][1] - + m[0][1]*m[1][0]*m[2][2]*m[3][3] + + m[0][1]*m[1][0]*m[2][3]*m[3][2] + + m[0][1]*m[1][2]*m[2][0]*m[3][3] - + m[0][1]*m[1][2]*m[2][3]*m[3][0] - + m[0][1]*m[1][3]*m[2][0]*m[3][2] + + m[0][1]*m[1][3]*m[2][2]*m[3][0] + + m[0][2]*m[1][0]*m[2][1]*m[3][3] - + m[0][2]*m[1][0]*m[2][3]*m[3][1] - + m[0][2]*m[1][1]*m[2][0]*m[3][3] + + m[0][2]*m[1][1]*m[2][3]*m[3][0] + + m[0][2]*m[1][3]*m[2][0]*m[3][1] - + m[0][2]*m[1][3]*m[2][1]*m[3][0] - + m[0][3]*m[1][0]*m[2][1]*m[3][2] + + m[0][3]*m[1][0]*m[2][2]*m[3][1] + + m[0][3]*m[1][1]*m[2][0]*m[3][2] - + m[0][3]*m[1][1]*m[2][2]*m[3][0] - + m[0][3]*m[1][2]*m[2][0]*m[3][1] + + m[0][3]*m[1][2]*m[2][1]*m[3][0] +} + +type A []A + +// A sequence of constant indexings. +func IndexChain1(s A) A { + return s[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] +} + +// A sequence of non-constant indexings. +func IndexChain2(s A, i int) A { + return s[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i] +} + +// Another sequence of indexings. +func IndexChain3(s []int) int { + return s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[0]]]]]]]]]]]]]]]]]]]]] +} + +// A right-leaning tree of byte multiplications. +func righttree(a, b, c, d uint8) uint8 { + return a * (b * (c * (d * + (a * (b * (c * (d * + (a * (b * (c * (d * + (a * (b * (c * (d * + (a * (b * (c * (d * + a * (b * (c * d))))))))))))))))))))) + +} + +// A left-leaning tree of byte multiplications. +func lefttree(a, b, c, d uint8) uint8 { + return ((((((((((((((((((a * b) * c) * d * + a) * b) * c) * d * + a) * b) * c) * d * + a) * b) * c) * d * + a) * b) * c) * d * + a) * b) * c) * d) +} + +type T struct { + Next I +} + +type I interface{} + +// A chains of type assertions. +func ChainT(t *T) *T { + return t. + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T). + Next.(*T) +} + +type U struct { + Children []J +} + +func (u *U) Child(n int) J { return u.Children[n] } + +type J interface { + Child(n int) J +} + +func ChainUAssert(u *U) *U { + return u.Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U). + Child(0).(*U) +} + +func ChainUNoAssert(u *U) *U { + return u.Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0). + Child(0).(*U) +} + +// Type assertions and slice indexing. See issue 4207. +func ChainAssertIndex(u *U) J { + return u. + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0].(*U). + Children[0] +} + +type UArr struct { + Children [2]J +} + +func (u *UArr) Child(n int) J { return u.Children[n] } + +func ChainAssertArrayIndex(u *UArr) J { + return u. + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0].(*UArr). + Children[0] +} + +type UArrPtr struct { + Children *[2]J +} + +func (u *UArrPtr) Child(n int) J { return u.Children[n] } + +func ChainAssertArrayptrIndex(u *UArrPtr) J { + return u. + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0].(*UArrPtr). + Children[0] +} + +// Chains of divisions. See issue 4201. + +func ChainDiv(a, b int) int { + return a / b / a / b / a / b / a / b / + a / b / a / b / a / b / a / b / + a / b / a / b / a / b / a / b +} + +func ChainDivRight(a, b int) int { + return a / (b / (a / (b / + (a / (b / (a / (b / + (a / (b / (a / (b / + (a / (b / (a / (b / + (a / (b / (a / b)))))))))))))))))) +} + +func ChainDivConst(a int) int { + return a / 17 / 17 / 17 / + 17 / 17 / 17 / 17 / + 17 / 17 / 17 / 17 +} + +func ChainMulBytes(a, b, c byte) byte { + return a*(a*(a*(a*(a*(a*(a*(a*(a*b+c)+c)+c)+c)+c)+c)+c)+c) + c +} diff --git a/test/typecheck.go b/test/typecheck.go new file mode 100644 index 000000000..239ceacc6 --- /dev/null +++ b/test/typecheck.go @@ -0,0 +1,18 @@ +// errorcheck + +// Verify that the Go compiler will not +// die after running into an undefined +// type in the argument list for a +// function. +// Does not compile. + +package main + +func mine(int b) int { // ERROR "undefined.*b" + return b + 2 // ERROR "undefined.*b" +} + +func main() { + mine() + c = mine() // ERROR "undefined.*c" "cannot assign to c" +} diff --git a/test/typeswitch3.go b/test/typeswitch3.go index 5475a8a6d..287e32e71 100644 --- a/test/typeswitch3.go +++ b/test/typeswitch3.go @@ -36,7 +36,7 @@ func main(){ } // Issue 2827. - switch _ := r.(type) { // ERROR "invalid variable name _" + switch _ := r.(type) { // ERROR "invalid variable name _|no new variables" } } diff --git a/test/zerodivide.go b/test/zerodivide.go index 673d1d18d..9ab271353 100644 --- a/test/zerodivide.go +++ b/test/zerodivide.go @@ -237,4 +237,7 @@ func main() { fmt.Printf("%v/%v: expected %g error; got %g\n", t.f, t.g, t.out, x) } } + if bad { + panic("zerodivide") + } } |