]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove ssagen/pgen_test.go
authorMatthew Dempsky <mdempsky@google.com>
Thu, 26 Aug 2021 22:30:40 +0000 (15:30 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 27 Aug 2021 00:36:45 +0000 (00:36 +0000)
This test was written in 2015, and hasn't had any meaningful changes
to it since. However, it's very ad hoc and pokes into internals that
it shouldn't, and it keeps getting in the way of more meaningful
refactorings. It doesn't even catch bugs; e.g., it didn't catch that
cmpstackvarlt wasn't asymmetric (CL 19778), and a bunch of its test
cases are bogus because we never actually use it to sort ir.PFUNC
nodes (assert added in this CL).

The compiler is woefully lacking in unit tests like these, but I
strongly feel this test is more of a hinderance than a help at the
moment.

Change-Id: I3ac7a3e533947aa95f325626c6eec13a43789f9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/345478
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/ssagen/pgen.go
src/cmd/compile/internal/ssagen/pgen_test.go [deleted file]

index 93157bfa11b56a93592ce93dc9f0bf621b307782..0ddf11b426b60de6d4c4f99482ebbddca16b8bf3 100644 (file)
@@ -75,7 +75,22 @@ func (s byStackVar) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
 // allocate space. In particular, it excludes arguments and results, which are in
 // the callers frame.
 func needAlloc(n *ir.Name) bool {
-       return n.Class == ir.PAUTO || n.Class == ir.PPARAMOUT && n.IsOutputParamInRegisters()
+       if n.Op() != ir.ONAME {
+               base.FatalfAt(n.Pos(), "%v has unexpected Op %v", n, n.Op())
+       }
+
+       switch n.Class {
+       case ir.PAUTO:
+               return true
+       case ir.PPARAM:
+               return false
+       case ir.PPARAMOUT:
+               return n.IsOutputParamInRegisters()
+
+       default:
+               base.FatalfAt(n.Pos(), "%v has unexpected Class %v", n, n.Class)
+               return false
+       }
 }
 
 func (s *ssafn) AllocFrame(f *ssa.Func) {
diff --git a/src/cmd/compile/internal/ssagen/pgen_test.go b/src/cmd/compile/internal/ssagen/pgen_test.go
deleted file mode 100644 (file)
index 69ed8ad..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-// 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.
-
-package ssagen
-
-import (
-       "reflect"
-       "sort"
-       "testing"
-
-       "cmd/compile/internal/ir"
-       "cmd/compile/internal/typecheck"
-       "cmd/compile/internal/types"
-       "cmd/internal/src"
-)
-
-func typeWithoutPointers() *types.Type {
-       return types.NewStruct(types.NoPkg, []*types.Field{
-               types.NewField(src.NoXPos, nil, types.New(types.TINT)),
-       })
-}
-
-func typeWithPointers() *types.Type {
-       return types.NewStruct(types.NoPkg, []*types.Field{
-               types.NewField(src.NoXPos, nil, types.NewPtr(types.New(types.TINT))),
-       })
-}
-
-func markUsed(n *ir.Name) *ir.Name {
-       n.SetUsed(true)
-       return n
-}
-
-func markNeedZero(n *ir.Name) *ir.Name {
-       n.SetNeedzero(true)
-       return n
-}
-
-// Test all code paths for cmpstackvarlt.
-func TestCmpstackvar(t *testing.T) {
-       nod := func(xoffset int64, t *types.Type, s *types.Sym, cl ir.Class) *ir.Name {
-               if s == nil {
-                       s = &types.Sym{Name: "."}
-               }
-               n := typecheck.NewName(s)
-               n.SetType(t)
-               n.SetFrameOffset(xoffset)
-               n.Class = cl
-               return n
-       }
-       testdata := []struct {
-               a, b *ir.Name
-               lt   bool
-       }{
-               {
-                       nod(0, nil, nil, ir.PAUTO),
-                       nod(0, nil, nil, ir.PFUNC),
-                       false,
-               },
-               {
-                       nod(0, nil, nil, ir.PFUNC),
-                       nod(0, nil, nil, ir.PAUTO),
-                       true,
-               },
-               {
-                       nod(0, nil, nil, ir.PFUNC),
-                       nod(10, nil, nil, ir.PFUNC),
-                       true,
-               },
-               {
-                       nod(20, nil, nil, ir.PFUNC),
-                       nod(10, nil, nil, ir.PFUNC),
-                       false,
-               },
-               {
-                       nod(10, nil, nil, ir.PFUNC),
-                       nod(10, nil, nil, ir.PFUNC),
-                       false,
-               },
-               {
-                       nod(10, nil, nil, ir.PPARAM),
-                       nod(20, nil, nil, ir.PPARAMOUT),
-                       true,
-               },
-               {
-                       nod(10, nil, nil, ir.PPARAMOUT),
-                       nod(20, nil, nil, ir.PPARAM),
-                       true,
-               },
-               {
-                       markUsed(nod(0, nil, nil, ir.PAUTO)),
-                       nod(0, nil, nil, ir.PAUTO),
-                       true,
-               },
-               {
-                       nod(0, nil, nil, ir.PAUTO),
-                       markUsed(nod(0, nil, nil, ir.PAUTO)),
-                       false,
-               },
-               {
-                       nod(0, typeWithoutPointers(), nil, ir.PAUTO),
-                       nod(0, typeWithPointers(), nil, ir.PAUTO),
-                       false,
-               },
-               {
-                       nod(0, typeWithPointers(), nil, ir.PAUTO),
-                       nod(0, typeWithoutPointers(), nil, ir.PAUTO),
-                       true,
-               },
-               {
-                       markNeedZero(nod(0, &types.Type{}, nil, ir.PAUTO)),
-                       nod(0, &types.Type{}, nil, ir.PAUTO),
-                       true,
-               },
-               {
-                       nod(0, &types.Type{}, nil, ir.PAUTO),
-                       markNeedZero(nod(0, &types.Type{}, nil, ir.PAUTO)),
-                       false,
-               },
-               {
-                       nod(0, &types.Type{Width: 1}, nil, ir.PAUTO),
-                       nod(0, &types.Type{Width: 2}, nil, ir.PAUTO),
-                       false,
-               },
-               {
-                       nod(0, &types.Type{Width: 2}, nil, ir.PAUTO),
-                       nod(0, &types.Type{Width: 1}, nil, ir.PAUTO),
-                       true,
-               },
-               {
-                       nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-                       nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, ir.PAUTO),
-                       true,
-               },
-               {
-                       nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-                       nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-                       false,
-               },
-               {
-                       nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, ir.PAUTO),
-                       nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-                       false,
-               },
-       }
-       for _, d := range testdata {
-               got := cmpstackvarlt(d.a, d.b)
-               if got != d.lt {
-                       t.Errorf("want %v < %v", d.a, d.b)
-               }
-               // If we expect a < b to be true, check that b < a is false.
-               if d.lt && cmpstackvarlt(d.b, d.a) {
-                       t.Errorf("unexpected %v < %v", d.b, d.a)
-               }
-       }
-}
-
-func TestStackvarSort(t *testing.T) {
-       nod := func(xoffset int64, t *types.Type, s *types.Sym, cl ir.Class) *ir.Name {
-               n := typecheck.NewName(s)
-               n.SetType(t)
-               n.SetFrameOffset(xoffset)
-               n.Class = cl
-               return n
-       }
-       inp := []*ir.Name{
-               nod(0, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(10, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(20, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               markUsed(nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO)),
-               nod(0, typeWithoutPointers(), &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO),
-               markNeedZero(nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO)),
-               nod(0, &types.Type{Width: 1}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{Width: 2}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, ir.PAUTO),
-       }
-       want := []*ir.Name{
-               nod(0, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(10, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               nod(20, &types.Type{}, &types.Sym{}, ir.PFUNC),
-               markUsed(nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO)),
-               markNeedZero(nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO)),
-               nod(0, &types.Type{Width: 2}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{Width: 1}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{Name: "abc"}, ir.PAUTO),
-               nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, ir.PAUTO),
-               nod(0, typeWithoutPointers(), &types.Sym{}, ir.PAUTO),
-       }
-       sort.Sort(byStackVar(inp))
-       if !reflect.DeepEqual(want, inp) {
-               t.Error("sort failed")
-               for i := range inp {
-                       g := inp[i]
-                       w := want[i]
-                       eq := reflect.DeepEqual(w, g)
-                       if !eq {
-                               t.Log(i, w, g)
-                       }
-               }
-       }
-}