Commit be66a226 by Ian Lance Taylor Committed by Ian Lance Taylor

Update Go testsuite to a copy of the Go 1.1.2 testsuite.

	* go.test/go-test.exp (go-find-packages): New proc.
	(go-gc-tests): Skip stress and safe tests.  Skip *.dir
	subdirectories.  Do simple +build line matching.  Handle run with
	arguments.  Handle errorcheckdir and rundircmpout.  Use packages
	for rundir.  Remove special handling for bug191 and dwarf.

From-SVN: r203578
parent 8088e1be
2013-10-14 Ian Lance Taylor <iant@google.com>
* go.test/go-test.exp (go-find-packages): New proc.
(go-gc-tests): Skip stress and safe tests. Skip *.dir
subdirectories. Do simple +build line matching. Handle run with
arguments. Handle errorcheckdir and rundircmpout. Use packages
for rundir. Remove special handling for bug191 and dwarf.
2013-10-14 Tobias Burnus <burnus@net-b.de> 2013-10-14 Tobias Burnus <burnus@net-b.de>
PR fortran/58658 PR fortran/58658
......
...@@ -242,6 +242,42 @@ proc go-set-goarch { } { ...@@ -242,6 +242,42 @@ proc go-set-goarch { } {
setenv GOARCH $goarch setenv GOARCH $goarch
} }
# Take a list of files and return a lists of lists, where each list is
# the set of files in the same package.
proc go-find-packages { test name files } {
set packages [list]
foreach f $files {
set fd [open $f r]
while 1 {
if { [gets $fd line] < 0 } {
close $fd
clone_output "$test: could not read $f"
unresolved $name
return [list]
}
if { [regexp "^package (\\w+)" $line match package] } {
set len [llength $packages]
for { set i 0 } { $i < $len } { incr i } {
set p [lindex $packages $i]
if { [lindex $p 0] == $package } {
lappend p $f
lset packages $i $p
break
}
}
if { $i >= $len } {
lappend packages [list $package $f]
}
close $fd
break
}
}
}
return $packages
}
proc go-gc-tests { } { proc go-gc-tests { } {
global srcdir subdir global srcdir subdir
global runtests global runtests
...@@ -286,12 +322,28 @@ proc go-gc-tests { } { ...@@ -286,12 +322,28 @@ proc go-gc-tests { } {
continue continue
} }
# Skip the files in stress; they are not tests.
if [string match "*go.test/test/stress/*" $test] {
continue
}
# Skip the files in safe; gccgo does not support safe mode.
if [string match "*go.test/test/safe/*" $test] {
continue
}
# Skip files in sub-subdirectories: they are components of # Skip files in sub-subdirectories: they are components of
# other tests. # other tests.
if [string match "*go.test/test/*/*/*" $test] { if [string match "*go.test/test/*/*/*" $test] {
continue continue
} }
# Skip files in *.dir subdirectories: they are components of
# other tests.
if [string match "*go.test/test/*.dir/*" $test] {
continue
}
set name [dg-trim-dirname $srcdir $test] set name [dg-trim-dirname $srcdir $test]
# Skip certain tests if target is RTEMS OS. # Skip certain tests if target is RTEMS OS.
...@@ -379,6 +431,21 @@ proc go-gc-tests { } { ...@@ -379,6 +431,21 @@ proc go-gc-tests { } {
continue continue
} }
if { [ string match "// +build *" $test_line ] } {
if { [ string match "*[getenv GOARCH]*" $test_line ] } {
continue
}
if { [ string match "*linux*" $test_line ] } {
continue
}
if { [ string match "*!windows*" $test_line ] } {
continue
}
close $fd
unsupported $name
set lines_ok 0
}
break break
} }
...@@ -407,7 +474,8 @@ proc go-gc-tests { } { ...@@ -407,7 +474,8 @@ proc go-gc-tests { } {
set go_compile_args "" set go_compile_args ""
set go_execute_args "" set go_execute_args ""
if { [regexp ".*\\\$A.out (\[^|&>2\].*)\$" $test_line match progargs] } { if { [regexp "// run (\[^|&>2\].*)\$" $test_line match progargs] \
&& ! [string match "*.go*" "$progargs"] } {
set go_execute_args $progargs set go_execute_args $progargs
verbose -log "$test: go_execute_args is $go_execute_args" verbose -log "$test: go_execute_args is $go_execute_args"
set index [string last " $progargs" $test_line] set index [string last " $progargs" $test_line]
...@@ -515,6 +583,27 @@ proc go-gc-tests { } { ...@@ -515,6 +583,27 @@ proc go-gc-tests { } {
go-execute-xfail $test go-execute-xfail $test
} elseif { $test_line == "// errorcheck" } { } elseif { $test_line == "// errorcheck" } {
errchk $test "" errchk $test ""
} elseif { $test_line == "// errorcheckdir" } {
set hold_runtests $runtests
set runtests "go-test.exp"
set dir "[file rootname $test].dir"
set files [lsort [glob "$dir/*.go"]]
set packages [go-find-packages $test $name $files]
if { [llength $packages] > 0 } {
set dg-do-what-default "assemble"
set del [list]
set last [lindex $packages end]
set packages [lreplace $packages end end]
foreach p $packages {
dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
lappend del "[file rootname [file tail [lindex $p 1]]].o"
}
errchk [lindex $last 1] "[lrange $last 2 end]"
foreach f $del {
file delete $f
}
}
set runtests $hold_runtests
} elseif { [string match "// errorcheckoutput*" $test_line] } { } elseif { [string match "// errorcheckoutput*" $test_line] } {
# Run the test to get a .go program to error check. # Run the test to get a .go program to error check.
set go_execute_args "" set go_execute_args ""
...@@ -557,21 +646,62 @@ proc go-gc-tests { } { ...@@ -557,21 +646,62 @@ proc go-gc-tests { } {
} elseif { $test_line == "// rundir" } { } elseif { $test_line == "// rundir" } {
set hold_runtests $runtests set hold_runtests $runtests
set runtests "go-test.exp" set runtests "go-test.exp"
set dg-do-what-default "assemble"
set dir "[file rootname $test].dir" set dir "[file rootname $test].dir"
set del {}
set files [lsort [glob "$dir/*.go"]] set files [lsort [glob "$dir/*.go"]]
set last [lindex $files end] set packages [go-find-packages $test $name $files]
set files [lreplace $files end end] if { [llength $packages] > 0 } {
foreach f $files { set dg-do-what-default "assemble"
dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS" set del [list]
lappend del "[file rootname [file tail $f]].o" set last [lindex $packages end]
set packages [lreplace $packages end end]
foreach p $packages {
dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
lappend del "[file rootname [file tail [lindex $p 1]]].o"
}
set dg-do-what-default "link"
set go_compile_args $del
go-torture-execute [lrange $last 1 end]
foreach f $del {
file delete $f
}
} }
set dg-do-what-default "link" set runtests $hold_runtests
set go_compile_args $del } elseif { $test_line == "// rundircmpout" } {
go-torture-execute $last set hold_runtests $runtests
foreach f $del { set runtests "go-test.exp"
file delete $f set dir "[file rootname $test].dir"
set files [lsort [glob "$dir/*.go"]]
set packages [go-find-packages $test $name $files]
if { [llength $packages] > 0 } {
set dg-do-what-default "assemble"
set del [list]
set last [lindex $packages end]
set packages [lreplace $packages end end]
foreach p $packages {
dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
lappend del "[file rootname [file tail [lindex $p 1]]].o"
}
set dg-do-what-default "link"
dg-test -keep-output [lrange $last 1 end] "$del -O" "-w $DEFAULT_GOCFLAGS"
set base "[file rootname [file tail [lindex $last 1]]]"
set output_file "./$base.exe"
lappend del $output_file
if [isnative] {
verbose -log "$output_file >$base.p 2>&1"
if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
verbose -log $catcherr
fail "$name execution"
untested "$name compare"
} else {
pass "$name execution"
regsub "\\.go$" "$test" ".out" expect
filecmp $expect $base.p "$name compare"
}
lappend del $base.p
}
foreach f $del {
file delete $f
}
} }
set runtests $hold_runtests set runtests $hold_runtests
} elseif { "$test_line" == "" } elseif { "$test_line" == ""
...@@ -709,33 +839,6 @@ proc go-gc-tests { } { ...@@ -709,33 +839,6 @@ proc go-gc-tests { } {
file delete $ofile1 $ofile2 $ofile3 $output_file file delete $ofile1 $ofile2 $ofile3 $output_file
set runtests $hold_runtests set runtests $hold_runtests
} elseif { [string match \ } elseif { [string match \
"// \$G \$D/bug191.dir/a.go && \$G \$D/bug191.dir/b.go && \$G \$D/\$F.go && \$L \$F.\$A" \
$test_line] } {
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "assemble"
regsub "\\.go$" $test ".dir/a.go" file1
dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
set ofile1 "[file rootname [file tail $file1]].o"
regsub "\\.go$" $test ".dir/b.go" file2
dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
set ofile2 "[file rootname [file tail $file2]].o"
dg-test -keep-output "$test" "-O" "-w $DEFAULT_GOCFLAGS"
set ofile3 "[file rootname [file tail $test]].o"
set dg-do-what-default "link"
set output_file "./[file rootname [file tail $test]].exe"
set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
$output_file "executable" "$options"]
set comp_output [go-dg-prune $target_triplet $comp_output]
if [string match "" $comp_output] {
pass $name
} else {
verbose -log $comp_output
fail $name
}
file delete $ofile1 $ofile2 $ofile3 $output_file
set runtests $hold_runtests
} elseif { [string match \
"// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \ "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
$test_line ] } { $test_line ] } {
set hold_runtests $runtests set hold_runtests $runtests
...@@ -949,10 +1052,6 @@ proc go-gc-tests { } { ...@@ -949,10 +1052,6 @@ proc go-gc-tests { } {
regsub "\\.go$" $test ".dir/a.go" file1 regsub "\\.go$" $test ".dir/a.go" file1
regsub "\\.go$" $test ".dir/b.go" file2 regsub "\\.go$" $test ".dir/b.go" file2
errchk "$file1" "$file2" errchk "$file1" "$file2"
} elseif { $test_line == "// \$G \$D/\$F.go \$D/z*.go && \$L \$F.\$A && ./\$A.out" } {
set dir [file dirname $test]
set go_compile_args [glob $dir/z*.go]
go-torture-execute $test
} elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \ } elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
&& $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \ && $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
&& $test_line3 == "// run" } { && $test_line3 == "// run" } {
......
...@@ -17,7 +17,7 @@ func main() { ...@@ -17,7 +17,7 @@ func main() {
case uint8: case uint8:
// ok // ok
default: default:
println("byte != uint8") panic("byte != uint8")
} }
x = uint8(2) x = uint8(2)
...@@ -25,7 +25,7 @@ func main() { ...@@ -25,7 +25,7 @@ func main() {
case byte: case byte:
// ok // ok
default: default:
println("uint8 != byte") panic("uint8 != byte")
} }
rune32 := false rune32 := false
...@@ -37,7 +37,7 @@ func main() { ...@@ -37,7 +37,7 @@ func main() {
// must be new code // must be new code
rune32 = true rune32 = true
default: default:
println("rune != int and rune != int32") panic("rune != int and rune != int32")
} }
if rune32 { if rune32 {
...@@ -49,6 +49,6 @@ func main() { ...@@ -49,6 +49,6 @@ func main() {
case rune: case rune:
// ok // ok
default: default:
println("int (or int32) != rune") panic("int (or int32) != rune")
} }
} }
// $G $F.go && $L $F.$A && ./$A.out arg1 arg2 // run arg1 arg2
// 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. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
...@@ -134,20 +134,31 @@ func main() { ...@@ -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{ var packages = []string{
"archive",
"archive/tar", "archive/tar",
"encoding/asn1", "archive/zip",
"math/big",
"bufio", "bufio",
"builtin",
"bytes", "bytes",
"math/cmplx", "compress",
"compress/bzip2",
"compress/flate", "compress/flate",
"compress/gzip", "compress/gzip",
"compress/lzw",
"compress/zlib", "compress/zlib",
"container",
"container/heap", "container/heap",
"container/list", "container/list",
"container/ring", "container/ring",
"crypto",
"crypto/aes", "crypto/aes",
"crypto/cipher",
"crypto/des",
"crypto/dsa",
"crypto/ecdsa",
"crypto/elliptic",
"crypto/hmac", "crypto/hmac",
"crypto/md5", "crypto/md5",
"crypto/rand", "crypto/rand",
...@@ -159,64 +170,111 @@ var packages = []string{ ...@@ -159,64 +170,111 @@ var packages = []string{
"crypto/subtle", "crypto/subtle",
"crypto/tls", "crypto/tls",
"crypto/x509", "crypto/x509",
"crypto/x509/pkix",
"database",
"database/sql",
"database/sql/driver",
"debug",
"debug/dwarf", "debug/dwarf",
"debug/macho",
"debug/elf", "debug/elf",
"debug/gosym", "debug/gosym",
"exp/ebnf", "debug/macho",
"debug/pe",
"encoding",
"encoding/ascii85", "encoding/ascii85",
"encoding/asn1",
"encoding/base32",
"encoding/base64", "encoding/base64",
"encoding/binary", "encoding/binary",
"encoding/csv",
"encoding/gob",
"encoding/hex", "encoding/hex",
"encoding/json",
"encoding/pem", "encoding/pem",
"os/exec", "encoding/xml",
"errors",
"expvar",
"flag", "flag",
"fmt", "fmt",
"go",
"go/ast", "go/ast",
"go/build",
"go/doc", "go/doc",
"go/format",
"go/parser", "go/parser",
"go/printer", "go/printer",
"go/scanner", "go/scanner",
"go/token", "go/token",
"encoding/gob",
"hash", "hash",
"hash/adler32", "hash/adler32",
"hash/crc32", "hash/crc32",
"hash/crc64", "hash/crc64",
"net/http", "hash/fnv",
"html",
"html/template",
"image", "image",
"image/color",
"image/draw",
"image/gif",
"image/jpeg", "image/jpeg",
"image/png", "image/png",
"index",
"index/suffixarray",
"io", "io",
"io/ioutil", "io/ioutil",
"encoding/json",
"log", "log",
"log/syslog",
"math", "math",
"math/big",
"math/cmplx",
"math/rand",
"mime", "mime",
"mime/multipart",
"net", "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", "os",
"os/exec",
"os/signal",
"os/user",
"path", "path",
"math/rand", "path/filepath",
"reflect", "reflect",
"regexp", "regexp",
"net/rpc", "regexp/syntax",
"runtime", "runtime",
"text/scanner", "runtime/cgo",
"runtime/debug",
"runtime/pprof",
"runtime/race",
"sort", "sort",
"net/smtp",
"strconv", "strconv",
"strings", "strings",
"sync", "sync",
"sync/atomic",
"syscall", "syscall",
"log/syslog",
"text/tabwriter",
"text/template",
"testing", "testing",
"testing/iotest", "testing/iotest",
"testing/quick", "testing/quick",
"text",
"text/scanner",
"text/tabwriter",
"text/template",
"text/template/parse",
"time", "time",
"unicode", "unicode",
"unicode/utf8",
"unicode/utf16", "unicode/utf16",
"encoding/xml", "unicode/utf8",
"unsafe",
} }
// 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 go1
// benchmark based on fmt/fmt_test.go
import (
"bytes"
"fmt"
"testing"
)
func BenchmarkFmtFprintfEmpty(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
fmt.Fprintf(&buf, "")
}
}
func BenchmarkFmtFprintfString(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "%s", "hello")
}
}
func BenchmarkFmtFprintfInt(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "%d", 5)
}
}
func BenchmarkFmtFprintfIntInt(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "%d %d", 5, 6)
}
}
func BenchmarkFmtFprintfPrefixedInt(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "This is some meaningless prefix text that needs to be scanned %d", 6)
}
}
func BenchmarkFmtFprintfFloat(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "%g", 5.23184)
}
}
func BenchmarkFmtManyArgs(b *testing.B) {
var buf bytes.Buffer
for i := 0; i < b.N; i++ {
buf.Reset()
fmt.Fprintf(&buf, "%2d/%2d/%2d %d:%d:%d %s %s\n", 3, 4, 5, 11, 12, 13, "hello", "world")
}
}
// 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 go1
import (
"bytes"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
// BenchmarkHTTPClientServer benchmarks both the HTTP client and the HTTP server,
// on small requests.
func BenchmarkHTTPClientServer(b *testing.B) {
msg := []byte("Hello world.\n")
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Write(msg)
}))
defer ts.Close()
tr := &http.Transport{}
defer tr.CloseIdleConnections()
cl := &http.Client{
Transport: tr,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, err := cl.Get(ts.URL)
if err != nil {
b.Fatal("Get:", err)
}
all, err := ioutil.ReadAll(res.Body)
if err != nil {
b.Fatal("ReadAll:", err)
}
if !bytes.Equal(all, msg) {
b.Fatalf("Got body %q; want %q", all, msg)
}
}
}
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
package go1 package go1
import ( import (
"bytes"
"compress/bzip2" "compress/bzip2"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil" "io/ioutil"
"strings"
"testing" "testing"
) )
...@@ -23,7 +23,7 @@ var ( ...@@ -23,7 +23,7 @@ var (
func makeJsonBytes() []byte { func makeJsonBytes() []byte {
var r io.Reader var r io.Reader
r = strings.NewReader(jsonbz2_base64) r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
r = base64.NewDecoder(base64.StdEncoding, r) r = base64.NewDecoder(base64.StdEncoding, r)
r = bzip2.NewReader(r) r = bzip2.NewReader(r)
b, err := ioutil.ReadAll(r) b, err := ioutil.ReadAll(r)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -33,7 +33,7 @@ func makeParserBytes() []byte { ...@@ -33,7 +33,7 @@ func makeParserBytes() []byte {
return b return b
} }
func BenchmarkParse(b *testing.B) { func BenchmarkGoParse(b *testing.B) {
b.SetBytes(int64(len(parserbytes))) b.SetBytes(int64(len(parserbytes)))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if _, err := parser.ParseFile(token.NewFileSet(), "", parserbytes, parser.ParseComments); err != nil { if _, err := parser.ParseFile(token.NewFileSet(), "", parserbytes, parser.ParseComments); err != nil {
......
// 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 go1
import (
"math/rand"
"regexp"
"testing"
)
// benchmark based on regexp/exec_test.go
var regexpText []byte
func makeRegexpText(n int) []byte {
rand.Seed(0) // For reproducibility.
if len(regexpText) >= n {
return regexpText[:n]
}
regexpText = make([]byte, n)
for i := range regexpText {
if rand.Intn(30) == 0 {
regexpText[i] = '\n'
} else {
regexpText[i] = byte(rand.Intn(0x7E+1-0x20) + 0x20)
}
}
return regexpText
}
func benchmark(b *testing.B, re string, n int) {
r := regexp.MustCompile(re)
t := makeRegexpText(n)
b.ResetTimer()
b.SetBytes(int64(n))
for i := 0; i < b.N; i++ {
if r.Match(t) {
b.Fatal("match!")
}
}
}
const (
easy0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
easy1 = "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$"
medium = "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
hard = "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
)
func BenchmarkRegexpMatchEasy0_32(b *testing.B) { benchmark(b, easy0, 32<<0) }
func BenchmarkRegexpMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) }
func BenchmarkRegexpMatchEasy1_32(b *testing.B) { benchmark(b, easy1, 32<<0) }
func BenchmarkRegexpMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) }
func BenchmarkRegexpMatchMedium_32(b *testing.B) { benchmark(b, medium, 1<<0) }
func BenchmarkRegexpMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) }
func BenchmarkRegexpMatchHard_32(b *testing.B) { benchmark(b, hard, 32<<0) }
func BenchmarkRegexpMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package go1
// benchmark based on time/time_test.go
import (
"testing"
"time"
)
func BenchmarkTimeParse(b *testing.B) {
for i := 0; i < b.N; i++ {
time.Parse(time.ANSIC, "Mon Jan 2 15:04:05 2006")
}
}
func BenchmarkTimeFormat(b *testing.B) {
t := time.Unix(1265346057, 0)
for i := 0; i < b.N; i++ {
t.Format("Mon Jan 2 15:04:05 2006")
}
}
...@@ -10,6 +10,14 @@ O=$GOCHAR ...@@ -10,6 +10,14 @@ O=$GOCHAR
GC="go tool ${O}g" GC="go tool ${O}g"
LD="go tool ${O}l" LD="go tool ${O}l"
gccm=""
case "$O" in
8)
gccm=-m32;;
6)
gccm=-m64;;
esac
PATH=.:$PATH PATH=.:$PATH
havegccgo=false havegccgo=false
...@@ -78,7 +86,7 @@ run() { ...@@ -78,7 +86,7 @@ run() {
fasta() { fasta() {
runonly echo 'fasta -n 25000000' 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 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio
run 'gc fasta' $O.out -n 25000000 run 'gc fasta' $O.out -n 25000000
run 'gc_B fasta' $O.out -n 25000000 run 'gc_B fasta' $O.out -n 25000000
...@@ -88,7 +96,7 @@ revcomp() { ...@@ -88,7 +96,7 @@ revcomp() {
runonly gcc -O2 fasta.c runonly gcc -O2 fasta.c
runonly a.out 25000000 > x runonly a.out 25000000 > x
runonly echo 'reverse-complement < output-of-fasta-25000000' 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 'gccgo -O2 reverse-complement.go' a.out < x
run 'gc reverse-complement' $O.out < x run 'gc reverse-complement' $O.out < x
run 'gc_B reverse-complement' $O.out < x run 'gc_B reverse-complement' $O.out < x
...@@ -97,7 +105,7 @@ revcomp() { ...@@ -97,7 +105,7 @@ revcomp() {
nbody() { nbody() {
runonly echo 'nbody -n 50000000' runonly echo 'nbody -n 50000000'
run 'gcc -O2 nbody.c -lm' a.out 50000000 run "gcc $gccm -O2 nbody.c -lm" a.out 50000000
run 'gccgo -O2 nbody.go' a.out -n 50000000 run 'gccgo -O2 nbody.go' a.out -n 50000000
run 'gc nbody' $O.out -n 50000000 run 'gc nbody' $O.out -n 50000000
run 'gc_B nbody' $O.out -n 50000000 run 'gc_B nbody' $O.out -n 50000000
...@@ -105,7 +113,7 @@ nbody() { ...@@ -105,7 +113,7 @@ nbody() {
binarytree() { binarytree() {
runonly echo 'binary-tree 15 # too slow to use 20' 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.go' a.out -n 15
run 'gccgo -O2 binary-tree-freelist.go' a.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' $O.out -n 15
...@@ -114,7 +122,7 @@ binarytree() { ...@@ -114,7 +122,7 @@ binarytree() {
fannkuch() { fannkuch() {
runonly echo 'fannkuch 12' 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.go' a.out -n 12
run 'gccgo -O2 fannkuch-parallel.go' a.out -n 12 run 'gccgo -O2 fannkuch-parallel.go' a.out -n 12
run 'gc fannkuch' $O.out -n 12 run 'gc fannkuch' $O.out -n 12
...@@ -126,7 +134,7 @@ regexdna() { ...@@ -126,7 +134,7 @@ regexdna() {
runonly gcc -O2 fasta.c runonly gcc -O2 fasta.c
runonly a.out 100000 > x runonly a.out 100000 > x
runonly echo 'regex-dna 100000' 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.go' a.out <x
run 'gccgo -O2 regex-dna-parallel.go' a.out <x run 'gccgo -O2 regex-dna-parallel.go' a.out <x
run 'gc regex-dna' $O.out <x run 'gc regex-dna' $O.out <x
...@@ -137,7 +145,7 @@ regexdna() { ...@@ -137,7 +145,7 @@ regexdna() {
spectralnorm() { spectralnorm() {
runonly echo 'spectral-norm 5500' 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 'gccgo -O2 spectral-norm.go' a.out -n 5500
run 'gc spectral-norm' $O.out -n 5500 run 'gc spectral-norm' $O.out -n 5500
run 'gc_B spectral-norm' $O.out -n 5500 run 'gc_B spectral-norm' $O.out -n 5500
...@@ -160,7 +168,7 @@ knucleotide() { ...@@ -160,7 +168,7 @@ knucleotide() {
mandelbrot() { mandelbrot() {
runonly echo 'mandelbrot 16000' 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 'gccgo -O2 mandelbrot.go' a.out -n 16000
run 'gc mandelbrot' $O.out -n 16000 run 'gc mandelbrot' $O.out -n 16000
run 'gc_B mandelbrot' $O.out -n 16000 run 'gc_B mandelbrot' $O.out -n 16000
...@@ -168,7 +176,7 @@ mandelbrot() { ...@@ -168,7 +176,7 @@ mandelbrot() {
meteor() { meteor() {
runonly echo 'meteor 2098' 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 'gccgo -O2 meteor-contest.go' a.out -n 2098
run 'gc meteor-contest' $O.out -n 2098 run 'gc meteor-contest' $O.out -n 2098
run 'gc_B meteor-contest' $O.out -n 2098 run 'gc_B meteor-contest' $O.out -n 2098
...@@ -176,7 +184,7 @@ meteor() { ...@@ -176,7 +184,7 @@ meteor() {
pidigits() { pidigits() {
runonly echo 'pidigits 10000' 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 'gccgo -O2 pidigits.go' a.out -n 10000
run 'gc pidigits' $O.out -n 10000 run 'gc pidigits' $O.out -n 10000
run 'gc_B pidigits' $O.out -n 10000 run 'gc_B pidigits' $O.out -n 10000
...@@ -184,14 +192,14 @@ pidigits() { ...@@ -184,14 +192,14 @@ pidigits() {
threadring() { threadring() {
runonly echo 'threadring 50000000' 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 'gccgo -O2 threadring.go' a.out -n 50000000
run 'gc threadring' $O.out -n 50000000 run 'gc threadring' $O.out -n 50000000
} }
chameneos() { chameneos() {
runonly echo 'chameneos 6000000' 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 'gccgo -O2 chameneosredux.go' a.out 6000000
run 'gc chameneosredux' $O.out 6000000 run 'gc chameneosredux' $O.out 6000000
} }
......
...@@ -15,18 +15,21 @@ type T struct { ...@@ -15,18 +15,21 @@ type T struct {
d byte d byte
} }
var a = []int{ 1, 2, 3 } var a = []int{1, 2, 3}
var NIL []int var NIL []int
func arraycmptest() { func arraycmptest() {
if NIL != nil { if NIL != nil {
println("fail1:", NIL, "!= nil") println("fail1:", NIL, "!= nil")
panic("bigalg")
} }
if nil != NIL { if nil != NIL {
println("fail2: nil !=", NIL) println("fail2: nil !=", NIL)
panic("bigalg")
} }
if a == nil || nil == a { if a == nil || nil == a {
println("fail3:", a, "== nil") println("fail3:", a, "== nil")
panic("bigalg")
} }
} }
...@@ -49,12 +52,14 @@ func maptest() { ...@@ -49,12 +52,14 @@ func maptest() {
t1 := mt[0] t1 := mt[0]
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { 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) println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
ma[1] = a ma[1] = a
a1 := ma[1] a1 := ma[1]
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("fail: map val array", a, a1) println("fail: map val array", a, a1)
panic("bigalg")
} }
} }
...@@ -72,15 +77,18 @@ func chantest() { ...@@ -72,15 +77,18 @@ func chantest() {
t1 := <-ct t1 := <-ct
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { 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) println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
a1 := <-ca a1 := <-ca
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("fail: map val array", a, a1) println("fail: map val array", a, a1)
panic("bigalg")
} }
} }
type E struct { } type E struct{}
var e E var e E
func interfacetest() { func interfacetest() {
...@@ -90,6 +98,7 @@ func interfacetest() { ...@@ -90,6 +98,7 @@ func interfacetest() {
a1 := i.([]int) a1 := i.([]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> []int", a, a1) println("interface <-> []int", a, a1)
panic("bigalg")
} }
pa := new([]int) pa := new([]int)
*pa = a *pa = a
...@@ -97,12 +106,14 @@ func interfacetest() { ...@@ -97,12 +106,14 @@ func interfacetest() {
a1 = *i.(*[]int) a1 = *i.(*[]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> *[]int", a, a1) println("interface <-> *[]int", a, a1)
panic("bigalg")
} }
i = t i = t
t1 := i.(T) t1 := i.(T)
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { 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) println("interface <-> struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
i = e i = e
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
package main package main
import (
"os"
"unsafe"
)
import _ "fmt" import _ "fmt"
var call string var call string
...@@ -102,8 +107,19 @@ func main() { ...@@ -102,8 +107,19 @@ func main() {
panic(sum) 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) h(a, b)
m() m()
} }
...@@ -133,14 +149,13 @@ func fp1(x, y int) { ...@@ -133,14 +149,13 @@ func fp1(x, y int) {
} }
} }
func m() { func m() {
var i I var i I
i = TI{} i = TI{}
i.M(1, 1) i.M(1, 1)
i.M(2, 2) i.M(2, 2)
fp(1, 1) fp(1, 1)
fp(2, 2) fp(2, 2)
} }
...@@ -162,4 +177,3 @@ func _() { ...@@ -162,4 +177,3 @@ func _() {
func ff() { func ff() {
var _ int = 1 var _ int = 1
} }
...@@ -9,8 +9,13 @@ ...@@ -9,8 +9,13 @@
package _ // ERROR "invalid package name _" package _ // ERROR "invalid package name _"
var t struct {
_ int
}
func main() { func main() {
_() // ERROR "cannot use _ as value" _() // ERROR "cannot use _ as value"
x := _+1 // ERROR "cannot use _ as value" x := _+1 // ERROR "cannot use _ as value"
_ = x _ = x
_ = t._ // ERROR "cannot refer to blank field|invalid use of"
} }
...@@ -47,7 +47,7 @@ func main() { ...@@ -47,7 +47,7 @@ func main() {
runtime.GC() runtime.GC()
runtime.ReadMemStats(memstats) runtime.ReadMemStats(memstats)
if memstats.Alloc-alloc > 1e5 { if memstats.Alloc-alloc > 1.1e5 {
println("BUG: too much memory for 100,000 selects:", memstats.Alloc-alloc) println("BUG: too much memory for 100,000 selects:", memstats.Alloc-alloc)
} }
} }
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
package main package main
import "unsafe" import (
"os"
"unsafe"
)
var global bool var global bool
func use(b bool) { global = b } func use(b bool) { global = b }
func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) } func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
...@@ -38,8 +42,12 @@ func main() { ...@@ -38,8 +42,12 @@ func main() {
var c string = "hello" var c string = "hello"
var d string = "hel" // try to get different pointer var d string = "hel" // try to get different pointer
d = d + "lo" 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) var e = make(chan int)
...@@ -283,7 +291,7 @@ func main() { ...@@ -283,7 +291,7 @@ func main() {
isfalse(ix != z) isfalse(ix != z)
isfalse(iz != x) isfalse(iz != x)
} }
// structs with _ fields // structs with _ fields
{ {
var x = struct { var x = struct {
...@@ -296,7 +304,7 @@ func main() { ...@@ -296,7 +304,7 @@ func main() {
x: 1, y: 2, z: 3, x: 1, y: 2, z: 3,
} }
var ix interface{} = x var ix interface{} = x
istrue(x == x) istrue(x == x)
istrue(x == ix) istrue(x == ix)
istrue(ix == x) istrue(ix == x)
......
...@@ -9,12 +9,23 @@ ...@@ -9,12 +9,23 @@
package main package main
type (
Float32 float32
Float64 float64
Complex64 complex64
Complex128 complex128
)
var ( var (
f32 float32 f32 float32
f64 float64 f64 float64
F32 Float32
F64 Float64
c64 complex64 c64 complex64
c128 complex128 c128 complex128
C64 Complex64
C128 Complex128
) )
func main() { func main() {
...@@ -25,4 +36,19 @@ func main() { ...@@ -25,4 +36,19 @@ func main() {
_ = complex128(0) // ok _ = complex128(0) // ok
_ = complex(f32, f64) // ERROR "complex" _ = complex(f32, f64) // ERROR "complex"
_ = complex(f64, f32) // ERROR "complex" _ = complex(f64, f32) // ERROR "complex"
_ = complex(f32, F32) // ERROR "complex"
_ = complex(F32, f32) // ERROR "complex"
_ = complex(f64, F64) // ERROR "complex"
_ = complex(F64, f64) // ERROR "complex"
c128 = complex(f32, f32) // ERROR "cannot use"
c64 = complex(f64, f64) // ERROR "cannot use"
c64 = complex(1.0, 2.0) // ok, constant is untyped
c128 = complex(1.0, 2.0)
C64 = complex(1.0, 2.0)
C128 = complex(1.0, 2.0)
C64 = complex(f32, f32) // ERROR "cannot use"
C128 = complex(f64, f64) // ERROR "cannot use"
} }
...@@ -45,4 +45,7 @@ func main() { ...@@ -45,4 +45,7 @@ func main() {
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x) fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
} }
} }
if bad {
panic("cmplxdivide failed.")
}
} }
...@@ -8,27 +8,29 @@ ...@@ -8,27 +8,29 @@
package main package main
import "os"
const ( const (
c0 = 0 c0 = 0
cm1 = -1 cm1 = -1
chuge = 1 << 100 chuge = 1 << 100
chuge_1 = chuge - 1 chuge_1 = chuge - 1
c1 = chuge >> 100 c1 = chuge >> 100
c3div2 = 3/2 c3div2 = 3 / 2
c1e3 = 1e3 c1e3 = 1e3
ctrue = true ctrue = true
cfalse = !ctrue cfalse = !ctrue
) )
const ( const (
f0 = 0.0 f0 = 0.0
fm1 = -1. fm1 = -1.
fhuge float64 = 1 << 100 fhuge float64 = 1 << 100
fhuge_1 float64 = chuge - 1 fhuge_1 float64 = chuge - 1
f1 float64 = chuge >> 100 f1 float64 = chuge >> 100
f3div2 = 3./2. f3div2 = 3. / 2.
f1e3 float64 = 1e3 f1e3 float64 = 1e3
) )
func assert(t bool, s string) { func assert(t bool, s string) {
...@@ -41,8 +43,8 @@ func ints() { ...@@ -41,8 +43,8 @@ func ints() {
assert(c0 == 0, "c0") assert(c0 == 0, "c0")
assert(c1 == 1, "c1") assert(c1 == 1, "c1")
assert(chuge > chuge_1, "chuge") assert(chuge > chuge_1, "chuge")
assert(chuge_1 + 1 == chuge, "chuge 1") assert(chuge_1+1 == chuge, "chuge 1")
assert(chuge + cm1 +1 == chuge, "cm1") assert(chuge+cm1+1 == chuge, "cm1")
assert(c3div2 == 1, "3/2") assert(c3div2 == 1, "3/2")
assert(c1e3 == 1000, "c1e3 int") assert(c1e3 == 1000, "c1e3 int")
assert(c1e3 == 1e3, "c1e3 float") assert(c1e3 == 1e3, "c1e3 float")
...@@ -81,9 +83,12 @@ func ints() { ...@@ -81,9 +83,12 @@ func ints() {
func floats() { func floats() {
assert(f0 == c0, "f0") assert(f0 == c0, "f0")
assert(f1 == c1, "f1") assert(f1 == c1, "f1")
assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1. // TODO(gri): exp/ssa/interp constant folding is incorrect.
assert(fhuge_1 + 1 == fhuge, "fhuge 1") if os.Getenv("GOSSAINTERP") == "" {
assert(fhuge + fm1 +1 == fhuge, "fm1") 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(f3div2 == 1.5, "3./2.")
assert(f1e3 == 1000, "f1e3 int") assert(f1e3 == 1000, "f1e3 int")
assert(f1e3 == 1.e3, "f1e3 float") assert(f1e3 == 1.e3, "f1e3 float")
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
package main package main
import "unsafe"
type I interface{} type I interface{}
const ( const (
...@@ -86,3 +88,7 @@ func main() { ...@@ -86,3 +88,7 @@ func main() {
} }
const ptr = nil // ERROR "const.*nil" 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|invalid constant type"
const _ = (*int)(nil) // ERROR "cannot be nil|invalid constant type"
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
package main package main
var b struct { var b struct {
a[10]int a [10]int
} }
var m map[string][20]int var m map[string][20]int
...@@ -61,17 +61,22 @@ var c1 = func() chan *[70]int { ...@@ -61,17 +61,22 @@ var c1 = func() chan *[70]int {
func main() { func main() {
if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 { if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {
println("BUG:", n1, n2, n3, n4, n5, n6, n7) println("BUG:", n1, n2, n3, n4, n5, n6, n7)
panic("fail")
} }
if !calledF { if !calledF {
println("BUG: did not call f") println("BUG: did not call f")
panic("fail")
} }
if <-c == nil { if <-c == nil {
println("BUG: did not receive from c") println("BUG: did not receive from c")
panic("fail")
} }
if !calledG { if !calledG {
println("BUG: did not call g") println("BUG: did not call g")
panic("fail")
} }
if <-c1 == nil { if <-c1 == nil {
println("BUG: did not receive from c1") println("BUG: did not receive from c1")
panic("fail")
} }
} }
...@@ -24,10 +24,10 @@ const ( ...@@ -24,10 +24,10 @@ const (
n2 = len(m[""]) n2 = len(m[""])
n3 = len(s[10]) n3 = len(s[10])
n4 = len(f()) // ERROR "must be constant|is not constant" n4 = len(f()) // ERROR "is not a constant|is not constant"
n5 = len(<-c) // ERROR "must be constant|is not constant" n5 = len(<-c) // ERROR "is not a constant|is not constant"
n6 = cap(f()) // ERROR "must be constant|is not constant" n6 = cap(f()) // ERROR "is not a constant|is not constant"
n7 = cap(<-c) // ERROR "must be constant|is not constant" n7 = cap(<-c) // ERROR "is not a constant|is not constant"
) )
// 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|incompatible types"
c8 = c2 == c6 // ERROR "mismatched types|incompatible types"
c9 = c1 == c6 // ERROR "mismatched types|incompatible types"
_ = c2 && (x < y)
_ = c2 && (1 < 2)
_ = c1 && c2 // ERROR "mismatched types|incompatible types"
_ = c2 && c6 // ERROR "mismatched types|incompatible types"
_ = c1 && c6 // ERROR "mismatched types|incompatible types"
)
...@@ -132,6 +132,7 @@ func verify8(length, in, out, m int) { ...@@ -132,6 +132,7 @@ func verify8(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -172,6 +173,7 @@ func verifyS(length, in, out, m int) { ...@@ -172,6 +173,7 @@ func verifyS(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -212,6 +214,7 @@ func verify16(length, in, out, m int) { ...@@ -212,6 +214,7 @@ func verify16(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -252,6 +255,7 @@ func verify32(length, in, out, m int) { ...@@ -252,6 +255,7 @@ func verify32(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -292,6 +296,7 @@ func verify64(length, in, out, m int) { ...@@ -292,6 +296,7 @@ func verify64(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
......
// 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
}
// $G $D/ddd2.go && $G $D/$F.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 2010 The Go Authors. All rights reserved. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
......
// skip // rundir
// Copyright 2010 The Go Authors. All rights reserved. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// This file is compiled and then imported by ddd3.go. // Test that variadic functions work across package boundaries.
package ddd
func Sum(args ...int) int {
s := 0
for _, v := range args {
s += v
}
return s
}
package ignored
...@@ -33,8 +33,9 @@ func main() { ...@@ -33,8 +33,9 @@ func main() {
m, h, s := f3() m, h, s := f3()
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
} }
if x() != "3" { if y := x(); y != "3" {
println("x() failed") println("x() failed", y)
panic("fail")
} }
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
} }
...@@ -41,7 +41,8 @@ func main() { ...@@ -41,7 +41,8 @@ func main() {
{ {
// multiline no new variables // multiline no new variables
i := f1 i := f1
i := func() { // ERROR "redeclared|no new|incompatible" i := func() int { // ERROR "redeclared|no new|incompatible"
return 0
} }
_ = i _ = i
} }
......
...@@ -25,6 +25,7 @@ func test1() { ...@@ -25,6 +25,7 @@ func test1() {
test1helper() test1helper()
if result != "9876543210" { if result != "9876543210" {
fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result) fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result)
panic("defer")
} }
} }
...@@ -41,6 +42,7 @@ func test2() { ...@@ -41,6 +42,7 @@ func test2() {
test2helper() test2helper()
if result != "9876543210" { if result != "9876543210" {
fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result) fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result)
panic("defer")
} }
} }
......
...@@ -13,36 +13,44 @@ import "fmt" ...@@ -13,36 +13,44 @@ import "fmt"
func f8(x, y, q, r int8) { func f8(x, y, q, r int8) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", 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) { func f16(x, y, q, r int16) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", 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) { func f32(x, y, q, r int32) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", 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) { func f64(x, y, q, r int64) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
panic("divide")
} }
} }
......
// 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
...@@ -31,7 +31,7 @@ if(@ARGV < 1) { ...@@ -31,7 +31,7 @@ if(@ARGV < 1) {
# Grab SOURCEFILES # Grab SOURCEFILES
foreach(reverse 0 .. @ARGV-1) { foreach(reverse 0 .. @ARGV-1) {
unless($ARGV[$_] =~ /\.go$/) { unless($ARGV[$_] =~ /\.(go|s)$/) {
@file = @ARGV[$_+1 .. @ARGV-1]; @file = @ARGV[$_+1 .. @ARGV-1];
last; last;
} }
......
...@@ -52,9 +52,11 @@ func chk(p, q *int, v int, s string) { ...@@ -52,9 +52,11 @@ func chk(p, q *int, v int, s string) {
func chkalias(p, q *int, v int, s string) { func chkalias(p, q *int, v int, s string) {
if p != q { if p != q {
println("want aliased pointers but got different after", s) println("want aliased pointers but got different after", s)
bad = true
} }
if *q != v+1 { if *q != v+1 {
println("wrong value want", v+1, "got", *q, "after", s) println("wrong value want", v+1, "got", *q, "after", s)
bad = true
} }
} }
......
// 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"
}
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
package main package main
func f (x, // GCCGO_ERROR "previous" func f (x, // GCCGO_ERROR "previous"
x int) { // ERROR "redeclared|redefinition" "duplicate" x int) { // ERROR "duplicate argument|redefinition"
} }
// $G $D/$F.dir/bug0.go && errchk $G $D/$F.dir/bug1.go // errorcheckdir
// 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. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
ignored package ignored
...@@ -20,7 +20,7 @@ Bus error ...@@ -20,7 +20,7 @@ Bus error
/* expected scope hierarchy (outermost to innermost) /* 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) "solar" scope (just holds the package name P so it can be found but doesn't conflict)
global scope (the package global scope) global scope (the package global scope)
local scopes (function scopes) local scopes (function scopes)
......
// $G $D/$F.dir/bug0.go && $G $D/$F.dir/bug1.go && errchk $G $D/$F.dir/bug2.go // errorcheckdir
// 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. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
ignored package ignored
// $G $D/bug160.dir/x.go && $G $D/bug160.dir/y.go && $L y.$A && ./$A.out // rundir
// 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. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
nothing to see here package ignored
// 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() {
}
// $G $D/bug191.dir/a.go && $G $D/bug191.dir/b.go && $G $D/$F.go && $L $F.$A // rundir
// 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. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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
}
...@@ -11,8 +11,8 @@ var s string; ...@@ -11,8 +11,8 @@ var s string;
var m map[string]int; var m map[string]int;
func main() { func main() {
println(t["hi"]); // ERROR "integer" println(t["hi"]); // ERROR "non-integer slice index|must be integer"
println(s["hi"]); // ERROR "integer" "to type uint" println(s["hi"]); // ERROR "non-integer string index|must be integer"
println(m[0]); // ERROR "map index" println(m[0]); // ERROR "cannot use.*as type string"
} }
...@@ -12,7 +12,7 @@ func g(x int, y float32) (...) // ERROR "[.][.][.]" "final argument" ...@@ -12,7 +12,7 @@ func g(x int, y float32) (...) // ERROR "[.][.][.]" "final argument"
func h(x, y ...int) // ERROR "[.][.][.]" 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" var x ...int; // ERROR "[.][.][.]|syntax|type"
......
...@@ -12,4 +12,4 @@ var c [1.5]int // ERROR "truncated" ...@@ -12,4 +12,4 @@ var c [1.5]int // ERROR "truncated"
var d ["abc"]int // ERROR "invalid array bound|not numeric" var d ["abc"]int // ERROR "invalid array bound|not numeric"
var e [nil]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 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"
...@@ -11,5 +11,5 @@ package main ...@@ -11,5 +11,5 @@ package main
type ByteSize float64 type ByteSize float64
const ( const (
_ = iota; // ignore first value by assigning to blank identifier _ = 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"
) )
// errchk $G -e $D/$F.dir/[ab].go // errorcheckdir
// 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. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: fails incorrectly // rundir
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Test case for issue 1402. // Test case for issue 1402.
ignored package ignored
// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out // rundir
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Test case for issue 1550 // Test case for issue 1550: a type cannot implement an interface
ignored // from another package with a private method, and type assertions
// should fail.
package ignored
...@@ -9,11 +9,7 @@ ...@@ -9,11 +9,7 @@
package p package p
type a interface { type a interface {
foo(x int) (x int) // ERROR "redeclared|redefinition" foo(x int) (x int) // ERROR "duplicate argument|redefinition"
}
var b interface {
bar(y int) (y int) // ERROR "redeclared|redefinition"
} }
/* /*
......
...@@ -15,7 +15,7 @@ func bla1() bool { ...@@ -15,7 +15,7 @@ func bla1() bool {
func bla5() bool { func bla5() bool {
_ = 1 _ = 1
false // ERROR "false not used|value computed is not used" false // ERROR "false evaluated but not used|value computed is not used"
_ = 2 _ = 2
return false return false
} }
......
// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: should not fail // rundir
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Issue 1536: bug when handling imported interfaces with
// private methods.
package ignored package ignored
...@@ -14,5 +14,5 @@ ...@@ -14,5 +14,5 @@
package main package main
func 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"
} }
// 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}
// $G $D/$F.dir/pkg.go && $G $D/$F.go || echo "Bug 382" // compiledir
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file // 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
// [ $A == 6 ] || errchk $G -e $D/$F.go // +build 386 arm
// errorcheck
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
...@@ -11,7 +9,7 @@ ...@@ -11,7 +9,7 @@
package main package main
func main() { func main() {
var arr [1000200030]int // ERROR "type .* too large" var arr [1000200030]int // GC_ERROR "type .* too large"
arr_bkup := arr arr_bkup := arr
_ = arr_bkup _ = arr_bkup
} }
\ No newline at end of file
// [ $A != 6 ] || errchk $G -e $D/$F.go // +build amd64
// errorcheck
// 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. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Issue 2444 // Issue 2444
// Issue 4666: issue with arrays of exactly 4GB.
package main package main
func main() { // ERROR "stack frame too large"
func main() { // GC_ERROR "stack frame too large"
var arr [1000200030]int32 var arr [1000200030]int32
arr_bkup := arr arr_bkup := arr
_ = arr_bkup _ = arr_bkup
} }
func F() { // GC_ERROR "stack frame too large"
var arr [1 << 30]int32
_ = arr[42]
}
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package p package p
type t struct { type t struct {
x int // ERROR "duplicate field x|duplicate field name .x." x int // GCCGO_ERROR "duplicate field name .x."
x int x int // GC_ERROR "duplicate field x"
} }
func f(t *t) int { func f(t *t) int {
......
...@@ -2,20 +2,20 @@ ...@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package p1 package p1
import "fmt" import "fmt"
type Fer interface { type Fer interface {
f() string f() string
} }
type Object struct {} type Object struct{}
func (this *Object) f() string { func (this *Object) f() string {
return "Object.f" return "Object.f"
} }
func PrintFer(fer Fer) { func PrintFer(fer Fer) {
fmt.Sprintln(fer.f()) fmt.Sprintln(fer.f())
} }
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package main
import "./p1" import "./p1"
type MyObject struct { type MyObject struct {
p1.Fer p1.Fer
} }
func main() { func main() {
var b p1.Fer = &p1.Object{} var b p1.Fer = &p1.Object{}
p1.PrintFer(b) p1.PrintFer(b)
var c p1.Fer = &MyObject{b} var c p1.Fer = &MyObject{b}
p1.PrintFer(c) p1.PrintFer(c)
} }
// $G $D/$F.dir/p1.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out // rundir
// 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. // Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Issue 1743: test embedding of imported types with private methods.
package ignored package ignored
// 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")
}
}
// $G $D/$F.dir/lib.go && $G $D/$F.go && $L $F.$A && ./$A.out // rundir
// 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. // Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
...@@ -12,91 +9,5 @@ ...@@ -12,91 +9,5 @@
// at which embedding level it is and in which order // at which embedding level it is and in which order
// embedding is done. // 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")
}
}
// 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)
}
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go && $G $D/$F.go && $L $F.$A && ./$A.out // rundir
// 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. // Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
...@@ -11,20 +8,4 @@ ...@@ -11,20 +8,4 @@
// interface defined in a third package, where the interface has a // interface defined in a third package, where the interface has a
// hidden method. This used to cause a link error with gccgo. // hidden method. This used to cause a link error with gccgo.
package main package ignored
import (
"./one"
"./two"
)
func F(i1 one.I1) {
switch v := i1.(type) {
case two.S2:
one.F1(v)
}
}
func main() {
F(nil)
}
// 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")
}
}
// 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")
}
}
// 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
}
// 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")
}
}
// 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{}{})
}
// 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]
}
// 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|depends upon itself"
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")
}
// 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
}
// 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"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment