1
0
mirror of https://github.com/golang/go synced 2024-11-17 16:54:44 -07:00

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>
This commit is contained in:
Keith Randall 2020-08-17 21:59:07 -07:00
parent 613388315e
commit a745171e6b
2 changed files with 30 additions and 1 deletions

View 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 {

View File

@ -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)
}
}
}
}