mirror of
https://github.com/golang/go
synced 2024-11-18 09:24:54 -07:00
e3c684777a
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>
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
// +build !nacl,!js
|
|
// run
|
|
|
|
// Copyright 2015 The Go 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 11771: Magic comments should ignore carriage returns.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
func main() {
|
|
if runtime.Compiler != "gc" {
|
|
return
|
|
}
|
|
|
|
dir, err := ioutil.TempDir("", "go-issue11771")
|
|
if err != nil {
|
|
log.Fatalf("creating temp dir: %v\n", err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
|
|
// The go:nowritebarrier magic comment is only permitted in
|
|
// the runtime package. So we confirm that the compilation
|
|
// fails.
|
|
|
|
var buf bytes.Buffer
|
|
fmt.Fprintln(&buf, `
|
|
package main
|
|
|
|
func main() {
|
|
}
|
|
`)
|
|
fmt.Fprintln(&buf, "//go:nowritebarrier\r")
|
|
fmt.Fprintln(&buf, `
|
|
func x() {
|
|
}
|
|
`)
|
|
|
|
if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
cmd := exec.Command("go", "tool", "compile", "x.go")
|
|
cmd.Dir = dir
|
|
output, err := cmd.CombinedOutput()
|
|
if err == nil {
|
|
log.Fatal("compile succeeded unexpectedly")
|
|
}
|
|
if !bytes.Contains(output, []byte("only allowed in runtime")) {
|
|
log.Fatalf("wrong error message from compiler; got:\n%s\n", output)
|
|
}
|
|
}
|