]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: skip unsupported tests for js/wasm
authorRichard Musiol <mail@richard-musiol.de>
Sun, 4 Mar 2018 11:15:37 +0000 (12:15 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 30 Apr 2018 19:39:18 +0000 (19:39 +0000)
The general policy for the current state of js/wasm is that it only
has to support tests that are also supported by nacl.

The test nilptr3.go makes assumptions about which nil checks can be
removed. Since WebAssembly does not signal on reading a null pointer,
all nil checks have to be explicit.

Updates #18892

Change-Id: I06a687860b8d22ae26b1c391499c0f5183e4c485
Reviewed-on: https://go-review.googlesource.com/110096
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

49 files changed:
src/archive/zip/zip_test.go
src/cmd/go/go_test.go
src/cmd/go/internal/base/signal_unix.go
src/cmd/vendor/github.com/google/pprof/internal/driver/fetch_test.go
src/cmd/vendor/github.com/google/pprof/internal/driver/webui_test.go
src/debug/elf/file_test.go
src/encoding/gob/encoder_test.go
src/internal/testenv/testenv.go
src/log/syslog/syslog_test.go
src/runtime/chanbarrier_test.go
src/runtime/crash_nonunix_test.go
src/runtime/gc_test.go
src/runtime/hash_test.go
src/runtime/pprof/pprof_test.go
src/runtime/proc_test.go
src/runtime/runtime_test.go
src/runtime/rwmutex_test.go
src/runtime/stack_test.go
src/syscall/syscall_test.go
src/text/template/exec.go
test/fixedbugs/bug248.go
test/fixedbugs/bug302.go
test/fixedbugs/bug345.go
test/fixedbugs/bug369.go
test/fixedbugs/bug429_run.go
test/fixedbugs/issue10958.go
test/fixedbugs/issue11656.go
test/fixedbugs/issue11771.go
test/fixedbugs/issue14636.go
test/fixedbugs/issue16037_run.go
test/fixedbugs/issue18902.go
test/fixedbugs/issue19182.go
test/fixedbugs/issue19658.go
test/fixedbugs/issue21317.go
test/fixedbugs/issue22660.go
test/fixedbugs/issue22662b.go
test/fixedbugs/issue9355.go
test/fixedbugs/issue9604b.go
test/fixedbugs/issue9862_run.go
test/gc2.go
test/linkmain_run.go
test/linkobj.go
test/linkx_run.go
test/live_syscall.go
test/nilptr3.go
test/nilptr3_wasm.go [new file with mode: 0644]
test/nosplit.go
test/peano.go
test/sinit_run.go

index 5adb87d5e3364e2af844a38d8b1c77caf4307a76..50218a2bbd72b807511dba594e880b9dc741e8b2 100644 (file)
@@ -15,6 +15,7 @@ import (
        "internal/testenv"
        "io"
        "io/ioutil"
+       "runtime"
        "sort"
        "strings"
        "testing"
@@ -461,6 +462,9 @@ func suffixIsZip64(t *testing.T, zip sizedReaderAt) bool {
 
 // Zip64 is required if the total size of the records is uint32max.
 func TestZip64LargeDirectory(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("skipping in short mode")
        }
index f5346570558bd759444f93aad925c9aa4288c84b..19e4116eb39ab38057f52b8c40ae9d2db1fdf3fd 100644 (file)
@@ -48,7 +48,7 @@ func tooSlow(t *testing.T) {
 
 func init() {
        switch runtime.GOOS {
-       case "android", "nacl":
+       case "android", "js", "nacl":
                canRun = false
        case "darwin":
                switch runtime.GOARCH {
index 4ca3da99226f8e141fd3b20af3282233a4d1c81c..38490b571bc23011fc67640015d8763c7ecbde04 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+// +build darwin dragonfly freebsd js linux nacl netbsd openbsd solaris
 
 package base
 
index f15328bfaee91235efbd65bb7af3e69a7a7ed15b..afb135b7cdda13d028812e65b785e5d1ae67d954 100644 (file)
@@ -361,7 +361,7 @@ func closedError() string {
 }
 
 func TestHttpsInsecure(t *testing.T) {
-       if runtime.GOOS == "nacl" {
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
                t.Skip("test assumes tcp available")
        }
        saveHome := os.Getenv(homeEnv())
index 7e061699ceb49f1ba30edf50bbf0bda8683559c3..328f1596d9fbfd2a13c1f020e72d196141397d78 100644 (file)
@@ -237,7 +237,7 @@ func makeFakeProfile() *profile.Profile {
 }
 
 func TestGetHostAndPort(t *testing.T) {
-       if runtime.GOOS == "nacl" {
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
                t.Skip("test assumes tcp available")
        }
 
index 880b66e7970d1d1f23dd34f41b3f78296aca112f..11d8992b714686c737f95e4d6fdbee9776eefcac 100644 (file)
@@ -784,7 +784,7 @@ func TestCompressedSection(t *testing.T) {
 func TestNoSectionOverlaps(t *testing.T) {
        // Ensure cmd/link outputs sections without overlaps.
        switch runtime.GOOS {
-       case "android", "darwin", "nacl", "plan9", "windows":
+       case "android", "darwin", "js", "nacl", "plan9", "windows":
                t.Skipf("cmd/link doesn't produce ELF binaries on %s", runtime.GOOS)
        }
        _ = net.ResolveIPAddr // force dynamic linkage
index a1ca252ccd11c2b0d83f2913d580cd42c8d6ae08..a41fc9e88978747942209fbd55125043134ff2b9 100644 (file)
@@ -10,6 +10,7 @@ import (
        "fmt"
        "io/ioutil"
        "reflect"
+       "runtime"
        "strings"
        "testing"
 )
@@ -1130,6 +1131,9 @@ func TestBadData(t *testing.T) {
 
 // TestHugeWriteFails tests that enormous messages trigger an error.
 func TestHugeWriteFails(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("out of memory on wasm")
+       }
        if testing.Short() {
                // Requires allocating a monster, so don't do this from all.bash.
                t.Skip("skipping huge allocation in short mode")
index b3c16a8e8727d991b7db61df6b0382cd964bc337..8f69fe0da5fbda3180502907fab9f11c47f18e6f 100644 (file)
@@ -41,7 +41,7 @@ func HasGoBuild() bool {
                return false
        }
        switch runtime.GOOS {
-       case "android", "nacl":
+       case "android", "nacl", "js":
                return false
        case "darwin":
                if strings.HasPrefix(runtime.GOARCH, "arm") {
@@ -114,7 +114,7 @@ func GoTool() (string, error) {
 // using os.StartProcess or (more commonly) exec.Command.
 func HasExec() bool {
        switch runtime.GOOS {
-       case "nacl":
+       case "nacl", "js":
                return false
        case "darwin":
                if strings.HasPrefix(runtime.GOARCH, "arm") {
@@ -149,13 +149,16 @@ func MustHaveExec(t testing.TB) {
 // HasExternalNetwork reports whether the current system can use
 // external (non-localhost) networks.
 func HasExternalNetwork() bool {
-       return !testing.Short()
+       return !testing.Short() && runtime.GOOS != "nacl" && runtime.GOOS != "js"
 }
 
 // MustHaveExternalNetwork checks that the current system can use
 // external (non-localhost) networks.
 // If not, MustHaveExternalNetwork calls t.Skip with an explanation.
 func MustHaveExternalNetwork(t testing.TB) {
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+               t.Skipf("skipping test: no external network on %s", runtime.GOOS)
+       }
        if testing.Short() {
                t.Skipf("skipping test: no external network in -short mode")
        }
index 1263be6d783b1ad4d9641d56d52aa432e1912cb4..6da3edd55565bf85f7262ea5ae09e2bd5d8c0879 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !windows,!nacl,!plan9
+// +build !windows,!nacl,!plan9,!js
 
 package syslog
 
index b6029fb04451f84e6a7149637fe496ea2ce17ecf..d4795748bf1ffdb696e5a65a518b710dfc482930 100644 (file)
@@ -57,7 +57,7 @@ func testChanSendBarrier(useSelect bool) {
        var globalMu sync.Mutex
        outer := 100
        inner := 100000
-       if testing.Short() {
+       if testing.Short() || runtime.GOARCH == "wasm" {
                outer = 10
                inner = 1000
        }
index 2ce995c06916fa3e64591c1e4511a770c34c7b9a..bf349a5d89d3c6508fcf4072e1785a6d6e5c32b1 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build windows plan9 nacl
+// +build windows plan9 nacl js,wasm
 
 package runtime_test
 
index 561061e3d82d9a151e9de4e506ab4fd20a566e91..d683d89fe405d92b527a425d09783534bcc6171d 100644 (file)
@@ -155,6 +155,10 @@ func TestHugeGCInfo(t *testing.T) {
 }
 
 func TestPeriodicGC(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no sysmon on wasm yet")
+       }
+
        // Make sure we're not in the middle of a GC.
        runtime.GC()
 
index 1400579cda8b89e98ffb43000b3085ecbb475321..7b8ebc4f3c00ff48fa453496073d6d4c841a73dc 100644 (file)
@@ -161,6 +161,9 @@ func TestSmhasherZeros(t *testing.T) {
 
 // Strings with up to two nonzero bytes all have distinct hashes.
 func TestSmhasherTwoNonzero(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("Too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("Skipping in short mode")
        }
@@ -229,6 +232,9 @@ func TestSmhasherCyclic(t *testing.T) {
 
 // Test strings with only a few bits set
 func TestSmhasherSparse(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("Too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("Skipping in short mode")
        }
@@ -264,6 +270,9 @@ func setbits(h *HashSet, b []byte, i int, k int) {
 // Test all possible combinations of n blocks from the set s.
 // "permutation" is a bad name here, but it is what Smhasher uses.
 func TestSmhasherPermutation(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("Too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("Skipping in short mode")
        }
@@ -433,6 +442,9 @@ func (k *IfaceKey) name() string {
 
 // Flipping a single bit of a key should flip each output bit with 50% probability.
 func TestSmhasherAvalanche(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("Too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("Skipping in short mode")
        }
@@ -508,6 +520,9 @@ func TestSmhasherWindowed(t *testing.T) {
        windowed(t, &BytesKey{make([]byte, 128)})
 }
 func windowed(t *testing.T, k Key) {
+       if GOARCH == "wasm" {
+               t.Skip("Too slow on wasm")
+       }
        if testing.Short() {
                t.Skip("Skipping in short mode")
        }
index 96fcfc9703b945d9d068e22488951c0452945a1c..e8567f495229f259ee91f5b1b938782c95fdfc32 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !nacl
+// +build !nacl,!js
 
 package pprof
 
index 2ece829071d41208b0073613298ba5eb043fb667..ad325987ac4d12f585cb7a567b031e015a42fabc 100644 (file)
@@ -28,6 +28,9 @@ func perpetuumMobile() {
 }
 
 func TestStopTheWorldDeadlock(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
        if testing.Short() {
                t.Skip("skipping during short test")
        }
@@ -230,6 +233,10 @@ func TestBlockLocked(t *testing.T) {
 }
 
 func TestTimerFairness(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
+
        done := make(chan bool)
        c := make(chan bool)
        for i := 0; i < 2; i++ {
@@ -256,6 +263,10 @@ func TestTimerFairness(t *testing.T) {
 }
 
 func TestTimerFairness2(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
+
        done := make(chan bool)
        c := make(chan bool)
        for i := 0; i < 2; i++ {
@@ -290,6 +301,10 @@ var preempt = func() int {
 }
 
 func TestPreemption(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
+
        // Test that goroutines are preempted at function calls.
        N := 5
        if testing.Short() {
@@ -313,6 +328,10 @@ func TestPreemption(t *testing.T) {
 }
 
 func TestPreemptionGC(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
+
        // Test that pending GC preempts running goroutines.
        P := 5
        N := 10
@@ -385,6 +404,9 @@ func TestNumGoroutine(t *testing.T) {
 }
 
 func TestPingPongHog(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no preemption on wasm yet")
+       }
        if testing.Short() {
                t.Skip("skipping in -short mode")
        }
@@ -834,6 +856,10 @@ func TestStealOrder(t *testing.T) {
 }
 
 func TestLockOSThreadNesting(t *testing.T) {
+       if runtime.GOARCH == "wasm" {
+               t.Skip("no threads on wasm yet")
+       }
+
        go func() {
                e, i := runtime.LockOSCounts()
                if e != 0 || i != 0 {
index d5b6b3ac3ce53e0a9ffe208e49fde63a469d36f6..8263d4059a9e928d90317f7c656f8336b40f64e2 100644 (file)
@@ -169,6 +169,9 @@ func testSetPanicOnFault(t *testing.T, addr uintptr, nfault *int) {
        if GOOS == "nacl" {
                t.Skip("nacl doesn't seem to fault on high addresses")
        }
+       if GOOS == "js" {
+               t.Skip("js does not support catching faults")
+       }
 
        defer func() {
                if err := recover(); err != nil {
@@ -264,7 +267,7 @@ func TestTrailingZero(t *testing.T) {
 }
 
 func TestBadOpen(t *testing.T) {
-       if GOOS == "windows" || GOOS == "nacl" {
+       if GOOS == "windows" || GOOS == "nacl" || GOOS == "js" {
                t.Skip("skipping OS that doesn't have open/read/write/close")
        }
        // make sure we get the correct error code if open fails. Same for
index 872b3b098e866b2db4a390b992ea3f6e4224594b..291a32ea5ec31975231223b13cfce74319db943a 100644 (file)
@@ -47,6 +47,9 @@ func doTestParallelReaders(numReaders int) {
 }
 
 func TestParallelRWMutexReaders(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("wasm has no threads yet")
+       }
        defer GOMAXPROCS(GOMAXPROCS(-1))
        // If runtime triggers a forced GC during this test then it will deadlock,
        // since the goroutines can't be stopped/preempted.
index 91d10bad5c57e9cbb1c63fe3575df87958f15b11..81a637ccb396caa0672577f2ff9ca1c02ddf500f 100644 (file)
@@ -76,6 +76,10 @@ func TestStackMem(t *testing.T) {
 
 // Test stack growing in different contexts.
 func TestStackGrowth(t *testing.T) {
+       if GOARCH == "wasm" {
+               t.Skip("fails on wasm (too slow?)")
+       }
+
        // Don't make this test parallel as this makes the 20 second
        // timeout unreliable on slow builders. (See issue #19381.)
 
index c3fffda2df59ab1f59d6b2b0ccbc772f8d6f568c..2a9d90e64c646314c631aa9590a1dc56da235f26 100644 (file)
@@ -62,8 +62,8 @@ func TestExecErrPermutedFds(t *testing.T) {
 }
 
 func TestGettimeofday(t *testing.T) {
-       if runtime.GOOS == "nacl" {
-               t.Skip("not implemented on nacl")
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+               t.Skip("not implemented on " + runtime.GOOS)
        }
        tv := &syscall.Timeval{}
        if err := syscall.Gettimeofday(tv); err != nil {
index 916be46b86921c53f9eb1aa82958604e784b9ace..8f8b5fe218c7f9ba0bb6b4e881cb94693bbbb6e8 100644 (file)
@@ -19,7 +19,14 @@ import (
 // templates. This limit is only practically reached by accidentally
 // recursive template invocations. This limit allows us to return
 // an error instead of triggering a stack overflow.
-const maxExecDepth = 100000
+var maxExecDepth = initMaxExecDepth()
+
+func initMaxExecDepth() int {
+       if runtime.GOARCH == "wasm" {
+               return 1000
+       }
+       return 100000
+}
 
 // state represents the state of an execution. It's not part of the
 // template so that multiple executions of the same template
index 30f2ce48f155bc43c5439eec6f07e402951906fe..a61620f23fe26c9e3e4b1e5f857a0a57a533681d 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,!plan9,!windows
+// +build !nacl,!js,!plan9,!windows
 // run
 
 // Copyright 2009 The Go Authors. All rights reserved.
index e4de25d5d00e8912126a06d0fd48e8019829668b..c763b87786e62981a734de84c02fc6b03e6dbed7 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2010 The Go Authors. All rights reserved.
index 59e99c7d2a39f1ef7b1a3f2abdabab05522194d9..af505c8a3bea13c3cb45a109a68b0a49330a4f67 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,!plan9,!windows
+// +build !nacl,!js,!plan9,!windows
 // run
 
 // Copyright 2011 The Go Authors. All rights reserved.
index 60162ab1cb8c757a8f50ff2b7bfc31767025c23d..e2a1147735c2646993716c8e3a69e336f6338134 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,!windows
+// +build !nacl,!js,!windows
 // run
 
 // Copyright 2011 The Go Authors. All rights reserved.
index 284033d1f7a133b940ccf553364513f8b647eba2..c6a02aae5ef7409a375ce9cc4c3f885c78d04209 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2014 The Go Authors. All rights reserved.
index 2b766941385bce2d0b0b1ad56fb4b47ad8761ce1..52487fb9bd61241010570ffdf24e06f486086727 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,disabled_see_issue_18589
+// +build !nacl,!js,disabled_see_issue_18589
 // buildrun -t 10  -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
 
 // Copyright 2016 The Go Authors. All rights reserved.
index c04a66202b63857de558d06c6d7cd876ae5c9781..451ae6348fa96321884ca7c612f7bcd3345e56cc 100644 (file)
@@ -9,6 +9,9 @@
 // doesn't go into the Go runtime.
 // +build !windows
 
+// wasm does not work, because the linear memory is not executable.
+// +build !wasm
+
 package main
 
 import (
index d91fc5d9662828045fb7ebd82301bc420d2f8fe6..99d7060d44e4b45f41940bc869492ca0a4e49737 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2015 The Go Authors. All rights reserved.
index 7d1b606241a2f1c20c15083ba0eacaee50d15093..6b342e4029bd8cff7d544a286d6e2d4406a953dc 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,!android,!darwin darwin,!arm
+// +build !nacl,!js,!android,!darwin darwin,!arm
 // run
 
 // Copyright 2016 The Go Authors. All rights reserved.
index 23fff5925b29430a4344c54199b0e8b50f5b1591..d05e3f7f3143cf2ec005ecff2b8fac20c6e44d91 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl,!android
+// +build !nacl,!js,!android
 // run
 
 // Copyright 2016 The Go Authors. All rights reserved.
index 78c92187ee3420c743d93489937bf658680b8689..9261ce7073de7ceac4eb5cc63383727267b91398 100644 (file)
@@ -1,5 +1,5 @@
 // run
-// +build !nacl
+// +build !nacl,!js
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 3a90ff4b26b8c7b0b1bb5ea42a58f2d95bd7fb92..e1f3ffb4749f4dbb4c2204c4a0f484aea91b4771 100644 (file)
@@ -1,4 +1,5 @@
 // run
+// +build !js
 
 // Copyright 2017 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 91cb88658e391ec7ecf7fdcd885ea069b22416b2..b2539629df0c45ad3a349db4068726b6c1e55b1b 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2017 The Go Authors. All rights reserved.
index ae0e0b55f9532bdb8d287b6094420e2af4b902f3..530694af1283370dd551fa5b35741038cb8e9246 100644 (file)
@@ -21,7 +21,7 @@ import (
 )
 
 func main() {
-       if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
+       if runtime.Compiler != "gc" || runtime.GOOS == "nacl" || runtime.GOOS == "js" {
                return
        }
 
index 48686fefee84119df48d040546301f2d3f83bf5d..b2282ea66531ec640e97ed9d89217d0f1d6889af 100644 (file)
@@ -19,7 +19,7 @@ import (
 )
 
 func main() {
-       if runtime.GOOS == "nacl" {
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
                return // no file system available on builders
        }
 
index 42c2a806d7d4797d1fec8b090e41e6549c20ac21..3594c0f4ef751fd13cd559da5c5f9c0e8ef42671 100644 (file)
@@ -36,8 +36,8 @@ var tests = []struct {
 }
 
 func main() {
-       if runtime.GOOS == "nacl" {
-               return // no file system available on builders
+       if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+               return // can not exec go tool
        }
 
        f, err := ioutil.TempFile("", "issue22662b.go")
index 10f8c7306916f509a3154bcefd9cc19414db4315..9657e644915f5c1dbd3ab91e9b5838357e242791 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func main() {
-       if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
+       if runtime.Compiler != "gc" || runtime.GOOS == "nacl" || runtime.GOOS == "js" {
                return
        }
 
index ebbd205baf0f28503441f6a82cc4d6eefe34c335..d32116b8573a5dee1809f1609873ce59f1cfe324 100644 (file)
@@ -4,6 +4,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// terribly slow on wasm
+// +build !wasm
+
 package main
 
 import (
index be22f40580add7fbe73980db699cbe1fa286ff76..299e8095450d8a97f0e27898c876ba8f1c6a1123 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2015 The Go Authors. All rights reserved.
index 31b36d8a08b5e957bf848507ca242f3f35a5da88..2f8eb9b70e66fdac06c40bf2dba4ccbdb27f78a3 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2011 The Go Authors. All rights reserved.
index 55de481a8185c21a4146751cf56dbf95b52acd81..68d53e8cad9a0e88e3f4dd3069881303dfea6e39 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2014 The Go Authors. All rights reserved.
index 8a86aa872f0362e989479498cceded42abce8691..2902d23f4b867074ba3b8d37a275507f3d5cfc41 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2016 The Go Authors. All rights reserved.
index cc249c9cfc2e221a75f5d57860e50538d15b6bca..ca9d31612ac3e482c2698848014c2eb79e3921f9 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2014 The Go Authors. All rights reserved.
index 6d954653cc5172a70fdd1a46f96096a2f01d27b1..65a161c028eb64f1f3ba7bae3392c05beab38964 100644 (file)
@@ -1,6 +1,6 @@
 // errorcheck -0 -m -live
 
-// +build !windows
+// +build !windows,!js
 
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 9a96bb53867341fb248a73c8b37e267d1fbc1e23..a22e60ef11f61ba2022e9d6c44be66870af8c73c 100644 (file)
@@ -1,5 +1,7 @@
 // errorcheck -0 -d=nil
 
+// +build !wasm
+
 // 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.
diff --git a/test/nilptr3_wasm.go b/test/nilptr3_wasm.go
new file mode 100644 (file)
index 0000000..9376d42
--- /dev/null
@@ -0,0 +1,270 @@
+// errorcheck -0 -d=nil
+
+// +build wasm
+
+// 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.
+
+// Test that nil checks are removed.
+// Optimization is enabled.
+
+package p
+
+type Struct struct {
+       X int
+       Y float64
+}
+
+type BigStruct struct {
+       X int
+       Y float64
+       A [1 << 20]int
+       Z string
+}
+
+type Empty struct {
+}
+
+type Empty1 struct {
+       Empty
+}
+
+var (
+       intp       *int
+       arrayp     *[10]int
+       array0p    *[0]int
+       bigarrayp  *[1 << 26]int
+       structp    *Struct
+       bigstructp *BigStruct
+       emptyp     *Empty
+       empty1p    *Empty1
+)
+
+func f1() {
+       _ = *intp // ERROR "generated nil check"
+
+       // This one should be removed but the block copy needs
+       // to be turned into its own pseudo-op in order to see
+       // the indirect.
+       _ = *arrayp // ERROR "generated nil check"
+
+       // 0-byte indirect doesn't suffice.
+       // we don't registerize globals, so there are no removed.* nil checks.
+       _ = *array0p // ERROR "generated nil check"
+       _ = *array0p // ERROR "removed nil check"
+
+       _ = *intp    // ERROR "removed nil check"
+       _ = *arrayp  // ERROR "removed nil check"
+       _ = *structp // ERROR "generated nil check"
+       _ = *emptyp  // ERROR "generated nil check"
+       _ = *arrayp  // ERROR "removed nil check"
+}
+
+func f2() {
+       var (
+               intp       *int
+               arrayp     *[10]int
+               array0p    *[0]int
+               bigarrayp  *[1 << 20]int
+               structp    *Struct
+               bigstructp *BigStruct
+               emptyp     *Empty
+               empty1p    *Empty1
+       )
+
+       _ = *intp       // ERROR "generated nil check"
+       _ = *arrayp     // ERROR "generated nil check"
+       _ = *array0p    // ERROR "generated nil check"
+       _ = *array0p    // ERROR "removed.* nil check"
+       _ = *intp       // ERROR "removed.* nil check"
+       _ = *arrayp     // ERROR "removed.* nil check"
+       _ = *structp    // ERROR "generated nil check"
+       _ = *emptyp     // ERROR "generated nil check"
+       _ = *arrayp     // ERROR "removed.* nil check"
+       _ = *bigarrayp  // ERROR "generated nil check" ARM removed nil check before indirect!!
+       _ = *bigstructp // ERROR "generated nil check"
+       _ = *empty1p    // ERROR "generated nil check"
+}
+
+func fx10k() *[10000]int
+
+var b bool
+
+func f3(x *[10000]int) {
+       // Using a huge type and huge offsets so the compiler
+       // does not expect the memory hardware to fault.
+       _ = x[9999] // ERROR "generated nil check"
+
+       for {
+               if x[9999] != 0 { // ERROR "removed nil check"
+                       break
+               }
+       }
+
+       x = fx10k()
+       _ = x[9999] // ERROR "generated nil check"
+       if b {
+               _ = x[9999] // ERROR "removed.* nil check"
+       } else {
+               _ = x[9999] // ERROR "removed.* nil check"
+       }
+       _ = x[9999] // ERROR "removed nil check"
+
+       x = fx10k()
+       if b {
+               _ = x[9999] // ERROR "generated nil check"
+       } else {
+               _ = x[9999] // ERROR "generated nil check"
+       }
+       _ = x[9999] // ERROR "generated nil check"
+
+       fx10k()
+       // This one is a bit redundant, if we figured out that
+       // x wasn't going to change across the function call.
+       // But it's a little complex to do and in practice doesn't
+       // matter enough.
+       _ = x[9999] // ERROR "removed nil check"
+}
+
+func f3a() {
+       x := fx10k()
+       y := fx10k()
+       z := fx10k()
+       _ = &x[9] // ERROR "generated nil check"
+       y = z
+       _ = &x[9] // ERROR "removed.* nil check"
+       x = y
+       _ = &x[9] // ERROR "generated nil check"
+}
+
+func f3b() {
+       x := fx10k()
+       y := fx10k()
+       _ = &x[9] // ERROR "generated nil check"
+       y = x
+       _ = &x[9] // ERROR "removed.* nil check"
+       x = y
+       _ = &x[9] // ERROR "removed.* nil check"
+}
+
+func fx10() *[10]int
+
+func f4(x *[10]int) {
+       // Most of these have no checks because a real memory reference follows,
+       // and the offset is small enough that if x is nil, the address will still be
+       // in the first unmapped page of memory.
+
+       _ = x[9] // ERROR "generated nil check" // bug: would like to remove this check (but nilcheck and load are in different blocks)
+
+       for {
+               if x[9] != 0 { // ERROR "removed nil check"
+                       break
+               }
+       }
+
+       x = fx10()
+       _ = x[9] // ERROR "generated nil check" // bug would like to remove before indirect
+       if b {
+               _ = x[9] // ERROR "removed nil check"
+       } else {
+               _ = x[9] // ERROR "removed nil check"
+       }
+       _ = x[9] // ERROR "removed nil check"
+
+       x = fx10()
+       if b {
+               _ = x[9] // ERROR "generated nil check"  // bug would like to remove before indirect
+       } else {
+               _ = &x[9] // ERROR "generated nil check"
+       }
+       _ = x[9] // ERROR "generated nil check"  // bug would like to remove before indirect
+
+       fx10()
+       _ = x[9] // ERROR "removed nil check"
+
+       x = fx10()
+       y := fx10()
+       _ = &x[9] // ERROR "generated nil check"
+       y = x
+       _ = &x[9] // ERROR "removed[a-z ]* nil check"
+       x = y
+       _ = &x[9] // ERROR "removed[a-z ]* nil check"
+}
+
+func f5(p *float32, q *float64, r *float32, s *float64) float64 {
+       x := float64(*p) // ERROR "generated nil check"
+       y := *q          // ERROR "generated nil check"
+       *r = 7           // ERROR "generated nil check"
+       *s = 9           // ERROR "generated nil check"
+       return x + y
+}
+
+type T [29]byte
+
+func f6(p, q *T) {
+       x := *p // ERROR "generated nil check"
+       *q = x  // ERROR "generated nil check"
+}
+
+func m1(m map[int][80]byte) byte {
+       v := m[3] // ERROR "removed nil check"
+       return v[5]
+}
+func m2(m map[int][800]byte) byte {
+       v := m[3] // ERROR "removed nil check"
+       return v[5]
+}
+func m3(m map[int][80]byte) (byte, bool) {
+       v, ok := m[3] // ERROR "removed nil check"
+       return v[5], ok
+}
+func m4(m map[int][800]byte) (byte, bool) {
+       v, ok := m[3] // ERROR "removed nil check"
+       return v[5], ok
+}
+func p1() byte {
+       p := new([100]byte)
+       return p[5] // ERROR "removed nil check"
+}
+
+// make sure not to do nil check for access of PAUTOHEAP
+//go:noinline
+func (p *Struct) m() {}
+func c1() {
+       var x Struct
+       func() { x.m() }() // ERROR "removed nil check"
+}
+
+type SS struct {
+       x byte
+}
+
+type TT struct {
+       SS
+}
+
+func f(t *TT) *byte {
+       // See issue 17242.
+       s := &t.SS  // ERROR "removed nil check"
+       return &s.x // ERROR "generated nil check"
+}
+
+// make sure not to do nil check for newobject
+func f7() (*Struct, float64) {
+       t := new(Struct)
+       p := &t.Y    // ERROR "removed nil check"
+       return t, *p // ERROR "removed nil check"
+}
+
+// make sure to remove nil check for memory move (issue #18003)
+func f8(t *[8]int) [8]int {
+       return *t // ERROR "generated nil check"
+}
+
+func f9() []int {
+       x := new([1]int)
+       x[0] = 1  // ERROR "removed nil check"
+       y := x[:] // ERROR "removed nil check"
+       return y
+}
index e6cecebde36dea2e8e070ea9274f11dc8af20c6f..e6cd04e563060ddb94a04d9356a6f99e5f01b322 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2014 The Go Authors. All rights reserved.
index 745f5153f6bcf7189af6864066ec597c12d0a8ea..1102a972444b8f6e1dd39795d93c35ff13a99f78 100644 (file)
@@ -9,6 +9,8 @@
 
 package main
 
+import "runtime"
+
 type Number *Number
 
 // -------------------------------------
@@ -116,7 +118,11 @@ var results = [...]int{
 }
 
 func main() {
-       for i := 0; i <= 9; i++ {
+       max := 9
+       if runtime.GOARCH == "wasm" {
+               max = 7 // stack size is limited
+       }
+       for i := 0; i <= max; i++ {
                if f := count(fact(gen(i))); f != results[i] {
                        println("FAIL:", i, "!:", f, "!=", results[i])
                        panic(0)
index c9afd3b77719a20bceb0b364ed470a477c735619..fdd19c492f5885244568e894b8ae21af78e787f5 100644 (file)
@@ -1,4 +1,4 @@
-// +build !nacl
+// +build !nacl,!js
 // run
 
 // Copyright 2014 The Go Authors. All rights reserved.