aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2020-08-17 21:59:07 -0700
committerKeith Randall <khr@golang.org>2020-08-18 05:23:42 +0000
commita745171e6b30394b661a040d04e8807b4bd0c7da (patch)
tree4d37fa49eb61bb831928a1fbd4d6955ccffed2e8
parent613388315e29d4e906805e602602500ca1e7e334 (diff)
downloadgo-a745171e6b30394b661a040d04e8807b4bd0c7da.tar.gz
go-a745171e6b30394b661a040d04e8807b4bd0c7da.zip
cmd/compile: fix SSA type comparison
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>
-rw-r--r--src/cmd/compile/internal/types/type.go3
-rw-r--r--src/cmd/compile/internal/types/type_test.go28
2 files changed, 30 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 3b7b31c5d6..91b54b43d4 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -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
index 0000000000..fe3f380b21
--- /dev/null
+++ b/src/cmd/compile/internal/types/type_test.go
@@ -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)
+ }
+ }
+ }
+}