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

cmd/compile: add type check for ssa genericOps

Change-Id: I2233a6a157ec8feffaefd6a8ee65b1c38778c1cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/255238
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Giovanni Bajo <rasky@develer.com>
This commit is contained in:
surechen 2020-09-17 09:02:59 +08:00 committed by Giovanni Bajo
parent 4c4a376736
commit 09dd2b004a

View File

@ -269,6 +269,38 @@ func checkFunc(f *Func) {
f.Fatalf("bad %s type: want uintptr, have %s", f.Fatalf("bad %s type: want uintptr, have %s",
v.Op, v.Type.String()) v.Op, v.Type.String())
} }
case OpStringLen:
if v.Type != c.Types.Int {
f.Fatalf("bad %s type: want int, have %s",
v.Op, v.Type.String())
}
case OpLoad:
if !v.Args[1].Type.IsMemory() {
f.Fatalf("bad arg 1 type to %s: want mem, have %s",
v.Op, v.Args[1].Type.String())
}
case OpStore:
if !v.Type.IsMemory() {
f.Fatalf("bad %s type: want mem, have %s",
v.Op, v.Type.String())
}
if !v.Args[2].Type.IsMemory() {
f.Fatalf("bad arg 2 type to %s: want mem, have %s",
v.Op, v.Args[2].Type.String())
}
case OpCondSelect:
if !v.Args[2].Type.IsBoolean() {
f.Fatalf("bad arg 2 type to %s: want boolean, have %s",
v.Op, v.Args[2].Type.String())
}
case OpAddPtr:
if !v.Args[0].Type.IsPtrShaped() && v.Args[0].Type != c.Types.Uintptr {
f.Fatalf("bad arg 0 type to %s: want ptr, have %s", v.Op, v.Args[0].LongString())
}
if !v.Args[1].Type.IsInteger() {
f.Fatalf("bad arg 1 type to %s: want integer, have %s", v.Op, v.Args[1].LongString())
}
} }
// TODO: check for cycles in values // TODO: check for cycles in values