aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssagen/pgen_test.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2021-08-27 08:06:55 -0400
committerMichael Matloob <matloob@golang.org>2021-08-27 08:06:57 -0400
commit220bc44a4c7b8ccc15c38f593531d5f0e721485c (patch)
treeac1b44473eef42e587c36bda6e097160634598a4 /src/cmd/compile/internal/ssagen/pgen_test.go
parentde83ef67acaaf5c2ce12dd831e8d3d04f02a6fc9 (diff)
parent67f7e16bcce0a3e68bf92e233ea16c8a9d2ac07a (diff)
downloadgo-dev.cmdgo.tar.gz
go-dev.cmdgo.zip
[dev.cmdgo] all: merge master (67f7e16) into dev.cmdgodev.cmdgo
Merge List: + 2021-08-27 67f7e16bcc encoding/gob: optimize decoding of []byte + 2021-08-27 2c60a99f72 cmd/compile/internal/syntax: make valid type parameter list in presence of errors + 2021-08-27 d350a66532 cmd/compile: eagerly CalcStructSize for synthetic ABI types + 2021-08-27 d7e2e2ec2b cmd/compile: delay fillinMethods to deal with mutually-recursive types + 2021-08-27 c927599783 cmd/compile: eliminate repetitive code + 2021-08-27 62f88b6dc8 cmd/compile: add types.RecalcSize + 2021-08-27 e7eee5e265 cmd/compile: remove ssagen/pgen_test.go + 2021-08-27 f153b6739b cmd/compile: use typecheck.InitUniverse in unit tests + 2021-08-26 967a8017f7 cmd/compile: move types init code into package types + 2021-08-26 af80af22b5 cmd/compile/internal/types2: do not declare new methods on instantiated types + 2021-08-26 03db2c2413 cmd/compile/internal/types2: implement TypeList.String (debugging support) + 2021-08-26 c9e05fdcf7 cmd/compile: fix reference to generic type needed by crawler + 2021-08-26 eb6a07fcf9 cmd/compile: unexport Type.Vargen + 2021-08-26 3836983779 cmd/compile/internal/types: unexport Type.Extra + 2021-08-26 1f8d4562de cmd/compile: change typecheck.iscmp into ir.Op.IsCmp Change-Id: I95c040a0e984a13a3b12c50458148007221ee300
Diffstat (limited to 'src/cmd/compile/internal/ssagen/pgen_test.go')
-rw-r--r--src/cmd/compile/internal/ssagen/pgen_test.go209
1 files changed, 0 insertions, 209 deletions
diff --git a/src/cmd/compile/internal/ssagen/pgen_test.go b/src/cmd/compile/internal/ssagen/pgen_test.go
deleted file mode 100644
index 69ed8ad74e9..00000000000
--- a/src/cmd/compile/internal/ssagen/pgen_test.go
+++ /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)
- }
- }
- }
-}