]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix SSA type comparison
authorKeith Randall <khr@golang.org>
Tue, 18 Aug 2020 04:59:07 +0000 (21:59 -0700)
committerKeith Randall <khr@golang.org>
Tue, 18 Aug 2020 05:23:42 +0000 (05:23 +0000)
A typo in the conversion code caused comparisons of SSA types to
report CMPeq when they were not in fact equal.

Fixes #40837

Change-Id: I0627eee51d524a585908b34a4590bc533c8415fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/248781
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/cmd/compile/internal/types/type.go
src/cmd/compile/internal/types/type_test.go [new file with mode: 0644]

index 3b7b31c5d60b4a65ddcf43a667fe888f4682596f..91b54b43d4807a56420de38f578ec026a7617219 100644 (file)
@@ -131,6 +131,7 @@ type Type struct {
        // TPTR: Ptr
        // TARRAY: *Array
        // TSLICE: Slice
+       // TSSA: string
        Extra interface{}
 
        // Width is the width of this Type in bytes.
@@ -1026,7 +1027,7 @@ func (t *Type) cmp(x *Type) Cmp {
 
        case TSSA:
                tname := t.Extra.(string)
-               xname := t.Extra.(string)
+               xname := x.Extra.(string)
                // desire fast sorting, not pretty sorting.
                if len(tname) == len(xname) {
                        if tname == xname {
diff --git a/src/cmd/compile/internal/types/type_test.go b/src/cmd/compile/internal/types/type_test.go
new file mode 100644 (file)
index 0000000..fe3f380
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2020 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 types_test
+
+import (
+       "cmd/compile/internal/types"
+       "testing"
+)
+
+func TestSSACompare(t *testing.T) {
+       a := []*types.Type{
+               types.TypeInvalid,
+               types.TypeMem,
+               types.TypeFlags,
+               types.TypeVoid,
+               types.TypeInt128,
+       }
+       for _, x := range a {
+               for _, y := range a {
+                       c := x.Compare(y)
+                       if x == y && c != types.CMPeq || x != y && c == types.CMPeq {
+                               t.Errorf("%s compare %s == %d\n", x.Extra, y.Extra, c)
+                       }
+               }
+       }
+}