]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: remove some unnecessary gotos
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 29 Apr 2018 13:17:23 +0000 (22:17 +0900)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 1 May 2018 10:46:08 +0000 (10:46 +0000)
Pick the low-hanging fruit, which are the gotos that don't go very far
and labels that aren't used often. All of them have easy replacements
with breaks and returns.

One slightly tricky rewrite is defaultlitreuse. We cannot use a defer
func to reset lineno, because one of its return paths does not reset
lineno, and thus broke toolstash -cmp.

Passes toolstash -cmp on std cmd.

Change-Id: Id1c0967868d69bb073addc7c5c3017ca91ff966f
Reviewed-on: https://go-review.googlesource.com/110063
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/walk.go
src/cmd/internal/obj/arm64/asm7.go
src/cmd/internal/obj/mips/asm0.go
src/cmd/internal/obj/mips/obj0.go
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/s390x/asmz.go

index cbb9c2ee08c1e265597ea4af96d2c79bb4e7b9fc..8d841b94ddf5b7f5129780dd5e972a3b7a3f0751 100644 (file)
@@ -1344,6 +1344,8 @@ func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
                default:
                        yyerror("defaultlit: unknown literal: %v", n)
                }
+               lineno = lno
+               return n
 
        case CTxxx:
                Fatalf("defaultlit: idealkind is CTxxx: %+v", n)
@@ -1354,28 +1356,19 @@ func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
                        t1 = t
                }
                n = convlit1(n, t1, false, reuse)
+               lineno = lno
+               return n
 
        case CTINT:
                t1 = types.Types[TINT]
-               goto num
-
        case CTRUNE:
                t1 = types.Runetype
-               goto num
-
        case CTFLT:
                t1 = types.Types[TFLOAT64]
-               goto num
-
        case CTCPLX:
                t1 = types.Types[TCOMPLEX128]
-               goto num
        }
 
-       lineno = lno
-       return n
-
-num:
        // Note: n.Val().Ctype() can be CTxxx (not a constant) here
        // in the case of an untyped non-constant value, like 1<<i.
        v1 := n.Val()
index ca6c95382f9875b84fe2ef43a3d5cdb9053d6429..a264bf340d34304c72f4b7c3fb2ae2c58bba21cf 100644 (file)
@@ -1008,7 +1008,8 @@ opswitch:
        case OCONV, OCONVNOP:
                if thearch.SoftFloat {
                        // For the soft-float case, ssa.go handles these conversions.
-                       goto oconv_walkexpr
+                       n.Left = walkexpr(n.Left, init)
+                       break
                }
                switch thearch.LinkArch.Family {
                case sys.ARM, sys.MIPS:
@@ -1062,8 +1063,6 @@ opswitch:
                                }
                        }
                }
-
-       oconv_walkexpr:
                n.Left = walkexpr(n.Left, init)
 
        case OANDNOT:
index 80a1f0bd3ab3472cd013d0b9eec0b93ccde5cf52..dd0e420e2fce1db2e872ac7bea5d46a92a5b1937 100644 (file)
@@ -1470,7 +1470,7 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
                case obj.NAME_NONE:
                        c.instoffset = a.Offset
                        if a.Reg != 0 && a.Reg != REGZERO {
-                               goto aconsize
+                               break
                        }
                        v := c.instoffset
                        if v == 0 {
@@ -1516,7 +1516,7 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
 
                case obj.NAME_EXTERN, obj.NAME_STATIC:
                        if a.Sym == nil {
-                               break
+                               return C_GOK
                        }
                        if a.Sym.Type == objabi.STLSBSS {
                                c.ctxt.Diag("taking address of TLS variable is not supported")
@@ -1531,7 +1531,6 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
                                a.Reg = obj.REG_NONE
                        }
                        c.instoffset = int64(c.autosize) + a.Offset
-                       goto aconsize
 
                case obj.NAME_PARAM:
                        if a.Reg == REGSP {
@@ -1540,11 +1539,10 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
                                a.Reg = obj.REG_NONE
                        }
                        c.instoffset = int64(c.autosize) + a.Offset + 8
-                       goto aconsize
+               default:
+                       return C_GOK
                }
-               return C_GOK
 
-       aconsize:
                if isaddcon(c.instoffset) {
                        return C_AACON
                }
index 0a391b978bb5cbda11226002dfd9e92df4822908..e4004be98d70c7cf4d6e8cb938790400cc6ea175 100644 (file)
@@ -612,13 +612,11 @@ func (c *ctxt0) aclass(a *obj.Addr) int {
                                return C_DACON
                        }
 
-                       goto consize
-
                case obj.NAME_EXTERN,
                        obj.NAME_STATIC:
                        s := a.Sym
                        if s == nil {
-                               break
+                               return C_GOK
                        }
 
                        c.instoffset = a.Offset
@@ -650,11 +648,11 @@ func (c *ctxt0) aclass(a *obj.Addr) int {
                                return C_SACON
                        }
                        return C_LACON
-               }
 
-               return C_GOK
+               default:
+                       return C_GOK
+               }
 
-       consize:
                if c.instoffset >= 0 {
                        if c.instoffset == 0 {
                                return C_ZCON
index 73026b46eaa644a51ee42641b99e17523532c374..697b2b7acb668dc94cac8c4fa860b79fbea7770d 100644 (file)
@@ -878,21 +878,20 @@ func (c *ctxt0) sched(p0, pe *obj.Prog) {
                        t = sch[j:]
                        if t[0].comp {
                                if s[0].p.Mark&BRANCH != 0 {
-                                       goto no2
+                                       continue
                                }
                        }
                        if t[0].p.Mark&DELAY != 0 {
                                if -cap(s) >= -cap(se) || conflict(&t[0], &s[1]) {
-                                       goto no2
+                                       continue
                                }
                        }
                        for u := t[1:]; -cap(u) <= -cap(s); u = u[1:] {
                                if c.depend(&u[0], &t[0]) {
-                                       goto no2
+                                       continue
                                }
                        }
                        goto out2
-               no2:
                }
 
                if s[0].p.Mark&BRANCH != 0 {
index 72738f1967e9d0b2f1d0ab926203e0572107c4b8..cf27a49cd0343859ba9685123f4617db1e3a2b00 100644 (file)
@@ -844,13 +844,11 @@ func (c *ctxt9) aclass(a *obj.Addr) int {
                                return C_DACON
                        }
 
-                       goto consize
-
                case obj.NAME_EXTERN,
                        obj.NAME_STATIC:
                        s := a.Sym
                        if s == nil {
-                               break
+                               return C_GOK
                        }
 
                        c.instoffset = a.Offset
@@ -871,11 +869,11 @@ func (c *ctxt9) aclass(a *obj.Addr) int {
                                return C_SACON
                        }
                        return C_LACON
-               }
 
-               return C_GOK
+               default:
+                       return C_GOK
+               }
 
-       consize:
                if c.instoffset >= 0 {
                        if c.instoffset == 0 {
                                return C_ZCON
index 761cdc563791220ace0bbb042a2309e64a7cde04..52cfc0e1e6804b6c3a8e94ac1d4eec16c96512e6 100644 (file)
@@ -570,13 +570,12 @@ func (c *ctxtz) aclass(a *obj.Addr) int {
                                }
                                return C_DACON
                        }
-                       goto consize
 
                case obj.NAME_EXTERN,
                        obj.NAME_STATIC:
                        s := a.Sym
                        if s == nil {
-                               break
+                               return C_GOK
                        }
                        c.instoffset = a.Offset
 
@@ -605,11 +604,11 @@ func (c *ctxtz) aclass(a *obj.Addr) int {
                                return C_SACON
                        }
                        return C_LACON
-               }
 
-               return C_GOK
+               default:
+                       return C_GOK
+               }
 
-       consize:
                if c.instoffset == 0 {
                        return C_ZCON
                }