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
This commit is contained in:
parent
8088e1beb2
commit
be66a22638
|
@ -1,3 +1,11 @@
|
|||
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>
|
||||
|
||||
PR fortran/58658
|
||||
|
|
|
@ -242,6 +242,42 @@ proc go-set-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 { } {
|
||||
global srcdir subdir
|
||||
global runtests
|
||||
|
@ -286,12 +322,28 @@ proc go-gc-tests { } {
|
|||
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
|
||||
# other tests.
|
||||
if [string match "*go.test/test/*/*/*" $test] {
|
||||
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]
|
||||
|
||||
# Skip certain tests if target is RTEMS OS.
|
||||
|
@ -379,6 +431,21 @@ proc go-gc-tests { } {
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -407,7 +474,8 @@ proc go-gc-tests { } {
|
|||
|
||||
set go_compile_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
|
||||
verbose -log "$test: go_execute_args is $go_execute_args"
|
||||
set index [string last " $progargs" $test_line]
|
||||
|
@ -515,6 +583,27 @@ proc go-gc-tests { } {
|
|||
go-execute-xfail $test
|
||||
} elseif { $test_line == "// errorcheck" } {
|
||||
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] } {
|
||||
# Run the test to get a .go program to error check.
|
||||
set go_execute_args ""
|
||||
|
@ -557,21 +646,62 @@ proc go-gc-tests { } {
|
|||
} elseif { $test_line == "// rundir" } {
|
||||
set hold_runtests $runtests
|
||||
set runtests "go-test.exp"
|
||||
set dg-do-what-default "assemble"
|
||||
set dir "[file rootname $test].dir"
|
||||
set del {}
|
||||
set files [lsort [glob "$dir/*.go"]]
|
||||
set last [lindex $files end]
|
||||
set files [lreplace $files end end]
|
||||
foreach f $files {
|
||||
dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
|
||||
lappend del "[file rootname [file tail $f]].o"
|
||||
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"
|
||||
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 go_compile_args $del
|
||||
go-torture-execute $last
|
||||
foreach f $del {
|
||||
file delete $f
|
||||
set runtests $hold_runtests
|
||||
} elseif { $test_line == "// rundircmpout" } {
|
||||
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"
|
||||
}
|
||||
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
|
||||
} elseif { "$test_line" == ""
|
||||
|
@ -708,33 +838,6 @@ proc go-gc-tests { } {
|
|||
$status $name
|
||||
file delete $ofile1 $ofile2 $ofile3 $output_file
|
||||
set runtests $hold_runtests
|
||||
} 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" \
|
||||
$test_line ] } {
|
||||
|
@ -949,10 +1052,6 @@ proc go-gc-tests { } {
|
|||
regsub "\\.go$" $test ".dir/a.go" file1
|
||||
regsub "\\.go$" $test ".dir/b.go" 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 &&" \
|
||||
&& $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
|
||||
&& $test_line3 == "// run" } {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
// $G $F.go && $L $F.$A && ./$A.out 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.
|
||||
// run arg1 arg2
|
||||
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
|
|
@ -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,64 +170,111 @@ 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",
|
||||
"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",
|
||||
"mime",
|
||||
"net",
|
||||
"os",
|
||||
"path",
|
||||
"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",
|
||||
"os/exec",
|
||||
"os/signal",
|
||||
"os/user",
|
||||
"path",
|
||||
"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",
|
||||
"text",
|
||||
"text/scanner",
|
||||
"text/tabwriter",
|
||||
"text/template",
|
||||
"text/template/parse",
|
||||
"time",
|
||||
"unicode",
|
||||
"unicode/utf8",
|
||||
"unicode/utf16",
|
||||
"encoding/xml",
|
||||
"unicode/utf8",
|
||||
"unsafe",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
// 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")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// 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 @@
|
|||
package go1
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/bzip2"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ var (
|
|||
|
||||
func makeJsonBytes() []byte {
|
||||
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 = bzip2.NewReader(r)
|
||||
b, err := ioutil.ReadAll(r)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,7 +33,7 @@ func makeParserBytes() []byte {
|
|||
return b
|
||||
}
|
||||
|
||||
func BenchmarkParse(b *testing.B) {
|
||||
func BenchmarkGoParse(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 {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
// 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) }
|
|
@ -0,0 +1,25 @@
|
|||
// 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
|
|||
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 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 'gc nbody' $O.out -n 50000000
|
||||
run 'gc_B nbody' $O.out -n 50000000
|
||||
|
@ -105,7 +113,7 @@ 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' a.out -n 15
|
||||
run 'gc binary-tree' $O.out -n 15
|
||||
|
@ -114,7 +122,7 @@ binarytree() {
|
|||
|
||||
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
|
||||
|
@ -160,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
|
||||
|
@ -168,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
|
||||
|
@ -176,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
|
||||
|
@ -184,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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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|invalid use of"
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go || echo BUG:bug434
|
||||
|
||||
// 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.
|
||||
|
||||
package ignored
|
|
@ -47,7 +47,7 @@ func main() {
|
|||
runtime.GC()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -9,12 +9,23 @@
|
|||
|
||||
package main
|
||||
|
||||
type (
|
||||
Float32 float32
|
||||
Float64 float64
|
||||
Complex64 complex64
|
||||
Complex128 complex128
|
||||
)
|
||||
|
||||
var (
|
||||
f32 float32
|
||||
f64 float64
|
||||
F32 Float32
|
||||
F64 Float64
|
||||
|
||||
c64 complex64
|
||||
c128 complex128
|
||||
C64 Complex64
|
||||
C128 Complex128
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -25,4 +36,19 @@ func main() {
|
|||
_ = complex128(0) // ok
|
||||
_ = complex(f32, f64) // 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() {
|
|||
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 @@
|
|||
|
||||
package main
|
||||
|
||||
const (
|
||||
c0 = 0
|
||||
cm1 = -1
|
||||
chuge = 1 << 100
|
||||
chuge_1 = chuge - 1
|
||||
c1 = chuge >> 100
|
||||
c3div2 = 3/2
|
||||
c1e3 = 1e3
|
||||
import "os"
|
||||
|
||||
ctrue = true
|
||||
const (
|
||||
c0 = 0
|
||||
cm1 = -1
|
||||
chuge = 1 << 100
|
||||
chuge_1 = chuge - 1
|
||||
c1 = chuge >> 100
|
||||
c3div2 = 3 / 2
|
||||
c1e3 = 1e3
|
||||
|
||||
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")
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type I interface{}
|
||||
|
||||
const (
|
||||
|
@ -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|invalid constant type"
|
||||
const _ = (*int)(nil) // ERROR "cannot be nil|invalid constant type"
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ const (
|
|||
n2 = len(m[""])
|
||||
n3 = len(s[10])
|
||||
|
||||
n4 = len(f()) // ERROR "must be constant|is not constant"
|
||||
n5 = len(<-c) // ERROR "must be constant|is not 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|is not constant"
|
||||
n7 = cap(<-c) // ERROR "must be constant|is not constant"
|
||||
n6 = cap(f()) // ERROR "is not a constant|is not constant"
|
||||
n7 = cap(<-c) // ERROR "is not a constant|is not constant"
|
||||
)
|
||||
|
||||
|
|
|
@ -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|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) {
|
|||
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
// $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.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ func main() {
|
|||
{
|
||||
// multiline no new variables
|
||||
i := f1
|
||||
i := func() { // ERROR "redeclared|no new|incompatible"
|
||||
i := func() int { // ERROR "redeclared|no new|incompatible"
|
||||
return 0
|
||||
}
|
||||
_ = i
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -31,7 +31,7 @@ if(@ARGV < 1) {
|
|||
|
||||
# Grab SOURCEFILES
|
||||
foreach(reverse 0 .. @ARGV-1) {
|
||||
unless($ARGV[$_] =~ /\.go$/) {
|
||||
unless($ARGV[$_] =~ /\.(go|s)$/) {
|
||||
@file = @ARGV[$_+1 .. @ARGV-1];
|
||||
last;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,9 @@ func foo12(yyy **int) { // ERROR "leaking param: yyy"
|
|||
xxx = yyy
|
||||
}
|
||||
|
||||
func foo13(yyy **int) { // ERROR "yyy does not escape"
|
||||
// Must treat yyy as leaking because *yyy leaks, and the escape analysis
|
||||
// summaries in exported metadata do not distinguish these two cases.
|
||||
func foo13(yyy **int) { // ERROR "leaking param: yyy"
|
||||
*xxx = *yyy
|
||||
}
|
||||
|
||||
|
@ -142,13 +144,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
|
||||
}
|
||||
|
@ -299,7 +301,8 @@ func (f *Foo) foo45() { // ERROR "f does not escape"
|
|||
F.x = f.x
|
||||
}
|
||||
|
||||
func (f *Foo) foo46() { // ERROR "f does not escape"
|
||||
// See foo13 above for explanation of why f leaks.
|
||||
func (f *Foo) foo46() { // ERROR "leaking param: f"
|
||||
F.xx = f.xx
|
||||
}
|
||||
|
||||
|
@ -561,12 +564,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"
|
||||
|
@ -574,7 +586,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() {
|
||||
|
@ -582,7 +594,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() {
|
||||
|
@ -590,7 +602,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() {
|
||||
|
@ -610,10 +622,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"
|
||||
}
|
||||
|
@ -646,6 +663,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()
|
||||
}
|
||||
|
@ -1079,29 +1111,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"
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
@ -1109,8 +1141,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
|
||||
}
|
||||
|
@ -1123,12 +1155,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
|
||||
}()
|
||||
}()
|
||||
|
@ -1136,40 +1168,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
|
||||
}()
|
||||
|
@ -1177,11 +1209,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
|
||||
}()
|
||||
|
@ -1189,11 +1221,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
|
||||
}()
|
||||
|
@ -1201,12 +1233,12 @@ 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
|
||||
}()
|
||||
}()
|
||||
|
@ -1216,7 +1248,7 @@ func foo138() *byte {
|
|||
type T struct {
|
||||
x [1]byte
|
||||
}
|
||||
t := new(T) // ERROR "new.T. escapes to heap"
|
||||
t := new(T) // ERROR "new.T. escapes to heap"
|
||||
return &t.x[0] // ERROR "&t.x.0. escapes to heap"
|
||||
}
|
||||
|
||||
|
@ -1226,6 +1258,70 @@ func foo139() *byte {
|
|||
y byte
|
||||
}
|
||||
}
|
||||
t := new(T) // ERROR "new.T. escapes to heap"
|
||||
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"
|
||||
}
|
||||
|
||||
type Tm struct {
|
||||
x int
|
||||
}
|
||||
|
||||
func (t *Tm) M() { // ERROR "t does not escape"
|
||||
}
|
||||
|
||||
func foo141() {
|
||||
var f func()
|
||||
|
||||
t := new(Tm) // ERROR "escapes to heap"
|
||||
f = t.M // ERROR "t.M does not escape"
|
||||
_ = f
|
||||
}
|
||||
|
||||
var gf func()
|
||||
|
||||
func foo142() {
|
||||
t := new(Tm) // ERROR "escapes to heap"
|
||||
gf = t.M // ERROR "t.M escapes to heap"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -7,5 +7,5 @@
|
|||
package main
|
||||
|
||||
func f (x, // GCCGO_ERROR "previous"
|
||||
x int) { // ERROR "redeclared|redefinition" "duplicate"
|
||||
x int) { // ERROR "duplicate argument|redefinition"
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// $G $D/$F.dir/bug0.go && errchk $G $D/$F.dir/bug1.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.
|
||||
// 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// $G $D/$F.dir/bug0.go && $G $D/$F.dir/bug1.go && errchk $G $D/$F.dir/bug2.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.
|
||||
// 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
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// $G $D/bug160.dir/x.go && $G $D/bug160.dir/y.go && $L y.$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.
|
||||
// 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
|
||||
|
|
|
@ -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() {
|
||||
}
|
|
@ -1,19 +1,9 @@
|
|||
// $G $D/bug191.dir/a.go && $G $D/bug191.dir/b.go && $G $D/$F.go && $L $F.$A
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
|
||||
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;
|
|||
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|must be integer"
|
||||
println(s["hi"]); // ERROR "non-integer string index|must be integer"
|
||||
println(m[0]); // ERROR "cannot use.*as type string"
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ 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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
// errchk $G -e $D/$F.dir/[ab].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.
|
||||
// errorcheckdir
|
||||
|
||||
// Copyright 2010 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: fails incorrectly
|
||||
|
||||
// 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.
|
||||
// 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
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$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.
|
||||
// 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
|
||||
|
|
|
@ -9,11 +9,7 @@
|
|||
package p
|
||||
|
||||
type a interface {
|
||||
foo(x int) (x int) // ERROR "redeclared|redefinition"
|
||||
}
|
||||
|
||||
var b interface {
|
||||
bar(y int) (y int) // ERROR "redeclared|redefinition"
|
||||
foo(x int) (x int) // ERROR "duplicate argument|redefinition"
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ./$A.out || echo BUG: should not fail
|
||||
|
||||
// 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.
|
||||
// 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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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}
|
|
@ -1,17 +1,9 @@
|
|||
// $G $D/$F.dir/pkg.go && $G $D/$F.go || echo "Bug 382"
|
||||
|
||||
// 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.
|
||||
// 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
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
// [ $A == 6 ] || errchk $G -e $D/$F.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.
|
||||
// +build 386 arm
|
||||
// errorcheck
|
||||
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
@ -11,7 +9,7 @@
|
|||
|
||||
package 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
// [ $A != 6 ] || errchk $G -e $D/$F.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.
|
||||
// +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"
|
||||
|
||||
func main() { // GC_ERROR "stack frame too large"
|
||||
var arr [1000200030]int32
|
||||
arr_bkup := arr
|
||||
_ = arr_bkup
|
||||
}
|
||||
|
||||
func F() { // GC_ERROR "stack frame too large"
|
||||
var arr [1 << 30]int32
|
||||
_ = arr[42]
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
package p
|
||||
|
||||
type t struct {
|
||||
x int // ERROR "duplicate field x|duplicate field name .x."
|
||||
x int
|
||||
x int // GCCGO_ERROR "duplicate field name .x."
|
||||
x int // GC_ERROR "duplicate field x"
|
||||
}
|
||||
|
||||
func f(t *t) int {
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
// $G $D/$F.dir/p1.go && $G $D/$F.dir/main.go && $L main.$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.
|
||||
// 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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
// $G $D/$F.dir/lib.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.
|
||||
// rundir
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
@ -12,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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.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.
|
||||
// rundir
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
@ -11,20 +8,4 @@
|
|||
// 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)
|
||||
}
|
||||
package ignored
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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{}{})
|
||||
}
|
|
@ -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]
|
||||
}
|
|
@ -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|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")
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue