From 09dd2b004aadb95887c4d6047ecb1a675a569ad2 Mon Sep 17 00:00:00 2001 From: surechen Date: Thu, 17 Sep 2020 09:02:59 +0800 Subject: [PATCH] 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 Reviewed-by: Giovanni Bajo Run-TryBot: Keith Randall TryBot-Result: Go Bot Trust: Giovanni Bajo --- src/cmd/compile/internal/ssa/check.go | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/cmd/compile/internal/ssa/check.go b/src/cmd/compile/internal/ssa/check.go index 9ce87e0aea..5f5dfc328a 100644 --- a/src/cmd/compile/internal/ssa/check.go +++ b/src/cmd/compile/internal/ssa/check.go @@ -269,6 +269,38 @@ func checkFunc(f *Func) { f.Fatalf("bad %s type: want uintptr, have %s", 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