]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add type check for ssa genericOps
authorsurechen <surechen17@gmail.com>
Thu, 17 Sep 2020 01:02:59 +0000 (09:02 +0800)
committerGiovanni Bajo <rasky@develer.com>
Fri, 18 Sep 2020 23:20:52 +0000 (23:20 +0000)
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>

src/cmd/compile/internal/ssa/check.go

index 9ce87e0aead6e22dcb94e8586b7270c653e414db..5f5dfc328a3f848bef815917988408719bb81018 100644 (file)
@@ -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