]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: fix block AuxIntType lookup
authorMichael Munday <mike.munday@ibm.com>
Fri, 11 Oct 2019 15:50:12 +0000 (08:50 -0700)
committerMichael Munday <mike.munday@ibm.com>
Fri, 11 Oct 2019 16:30:20 +0000 (16:30 +0000)
Avoid an out-of-range error when calling LongString on a generic
block.

Change-Id: I33ca88940d899bc71e3155bc63d2aa925cf83230
Reviewed-on: https://go-review.googlesource.com/c/go/+/200737
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/cmd/compile/internal/ssa/gen/main.go
src/cmd/compile/internal/ssa/opGen.go

index 93ddbf5477c3d9feeb653bd4af9f2aff3468cb5f..55ba338efa7fa342d47675d6bc3fc6db8359089c 100644 (file)
@@ -221,17 +221,19 @@ func genOp() {
        fmt.Fprintln(w, "func (k BlockKind) String() string {return blockString[k]}")
 
        // generate block kind auxint method
-       fmt.Fprintln(w, "var blockAuxIntType = [...]string{")
+       fmt.Fprintln(w, "func (k BlockKind) AuxIntType() string {")
+       fmt.Fprintln(w, "switch k {")
        for _, a := range archs {
                for _, b := range a.blocks {
                        if b.auxint == "" {
                                continue
                        }
-                       fmt.Fprintf(w, "Block%s%s:\"%s\",\n", a.Name(), b.name, b.auxint)
+                       fmt.Fprintf(w, "case Block%s%s: return \"%s\"\n", a.Name(), b.name, b.auxint)
                }
        }
        fmt.Fprintln(w, "}")
-       fmt.Fprintln(w, "func (k BlockKind) AuxIntType() string {return blockAuxIntType[k]}")
+       fmt.Fprintln(w, "return \"\"")
+       fmt.Fprintln(w, "}")
 
        // generate Op* declarations
        fmt.Fprintln(w, "const (")
index c30654dda7006f19308f67733790e5a25b9843c2..6ac86bbb9e96f2fac84b2180f76de2d68ceda865 100644 (file)
@@ -248,16 +248,20 @@ var blockString = [...]string{
 }
 
 func (k BlockKind) String() string { return blockString[k] }
-
-var blockAuxIntType = [...]string{
-       BlockS390XCIJ:   "Int8",
-       BlockS390XCGIJ:  "Int8",
-       BlockS390XCLIJ:  "UInt8",
-       BlockS390XCLGIJ: "UInt8",
+func (k BlockKind) AuxIntType() string {
+       switch k {
+       case BlockS390XCIJ:
+               return "Int8"
+       case BlockS390XCGIJ:
+               return "Int8"
+       case BlockS390XCLIJ:
+               return "UInt8"
+       case BlockS390XCLGIJ:
+               return "UInt8"
+       }
+       return ""
 }
 
-func (k BlockKind) AuxIntType() string { return blockAuxIntType[k] }
-
 const (
        OpInvalid Op = iota