| // 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. |
| if runtime.Compiler != "gc" { |
| dir, err := ioutil.TempDir("", "go-issue11771") |
| log.Fatalf("creating temp dir: %v\n", err) |
| // The go:nowritebarrier magic comment is only permitted in |
| // the runtime package. So we confirm that the compilation |
| fmt.Fprintln(&buf, "//go:nowritebarrier\r") |
| if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil { |
| cmd := exec.Command("go", "tool", "compile", "x.go") |
| output, err := cmd.CombinedOutput() |
| 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) |