Commit 9ecf899b authored by Daniel Martí's avatar Daniel Martí

cmd: remove some unnecessary gotos

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: default avatarMatthew Dempsky <mdempsky@google.com>
parent 030ac2c7
......@@ -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()
......
......@@ -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:
......
......@@ -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
}
......
......@@ -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
......
......@@ -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 {
......
......@@ -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
......
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment