From 9ecf899b295c3661bb6ad0e7345fb479986d13f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Sun, 29 Apr 2018 22:17:23 +0900 Subject: [PATCH] cmd: remove some unnecessary gotos MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 15 ++++----------- src/cmd/compile/internal/gc/walk.go | 5 ++--- src/cmd/internal/obj/arm64/asm7.go | 10 ++++------ src/cmd/internal/obj/mips/asm0.go | 10 ++++------ src/cmd/internal/obj/mips/obj0.go | 7 +++---- src/cmd/internal/obj/ppc64/asm9.go | 10 ++++------ src/cmd/internal/obj/s390x/asmz.go | 9 ++++----- 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index cbb9c2ee08..8d841b94dd 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -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<= 0 { if c.instoffset == 0 { return C_ZCON diff --git a/src/cmd/internal/obj/mips/obj0.go b/src/cmd/internal/obj/mips/obj0.go index 73026b46ea..697b2b7acb 100644 --- a/src/cmd/internal/obj/mips/obj0.go +++ b/src/cmd/internal/obj/mips/obj0.go @@ -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 { diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go index 72738f1967..cf27a49cd0 100644 --- a/src/cmd/internal/obj/ppc64/asm9.go +++ b/src/cmd/internal/obj/ppc64/asm9.go @@ -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 diff --git a/src/cmd/internal/obj/s390x/asmz.go b/src/cmd/internal/obj/s390x/asmz.go index 761cdc5637..52cfc0e1e6 100644 --- a/src/cmd/internal/obj/s390x/asmz.go +++ b/src/cmd/internal/obj/s390x/asmz.go @@ -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 } -- 2.50.0