]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: enable ssacheck for tests in ssa_test.go
authorCherry Zhang <cherryyz@google.com>
Mon, 6 Nov 2017 15:47:02 +0000 (10:47 -0500)
committerCherry Zhang <cherryyz@google.com>
Mon, 6 Nov 2017 19:56:53 +0000 (19:56 +0000)
I thought SSA check was enabled for those tests, but in fact it
was not. Enable it. So we have SSA check on for at least some
tests on all architectures.

Updates #22499.

Change-Id: I51fcdda3af7faab5aeb33bf46c6db309285ce42c
Reviewed-on: https://go-review.googlesource.com/76024
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa_test.go

index 40d80e6aba8fabd22610a2fde8eeab3135a9f3a8..462910a98668e0f80d7b06da999c092331febe42 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bytes"
        "internal/testenv"
        "io/ioutil"
+       "os"
        "os/exec"
        "path/filepath"
        "runtime"
@@ -27,11 +28,38 @@ func buildTest(t *testing.T, filename string) {
 }
 func doTest(t *testing.T, filename string, kind string) {
        testenv.MustHaveGoBuild(t)
+       gotool := testenv.GoToolPath(t)
+       tmpdir, ok := ioutil.TempDir("", "ssatest")
+       if ok != nil {
+               t.Fatalf("Failed to create temporary directory")
+       }
+       defer os.RemoveAll(tmpdir)
+
+       // Execute compile+link+run instead of "go run" to avoid applying -gcflags=-d=ssa/check/on
+       // to the runtime (especially over and over and over).
+       // compile
        var stdout, stderr bytes.Buffer
-       cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename))
+       cmd := exec.Command(gotool, "tool", "compile", "-d=ssa/check/on", "-o", filepath.Join(tmpdir, "run.a"), filepath.Join("testdata", filename))
        cmd.Stdout = &stdout
        cmd.Stderr = &stderr
-       if err := cmd.Run(); err != nil {
+       err := cmd.Run()
+       if kind == "run" {
+               if err == nil {
+                       // link
+                       cmd = exec.Command(gotool, "tool", "link", "-o", filepath.Join(tmpdir, "run.exe"), filepath.Join(tmpdir, "run.a"))
+                       cmd.Stdout = &stdout
+                       cmd.Stderr = &stderr
+                       err = cmd.Run()
+               }
+               if err == nil {
+                       // run
+                       cmd = exec.Command(filepath.Join(tmpdir, "run.exe"))
+                       cmd.Stdout = &stdout
+                       cmd.Stderr = &stderr
+                       err = cmd.Run()
+               }
+       }
+       if err != nil {
                t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
        }
        if s := stdout.String(); s != "" {