cmd/compile: keep JMPs around with -N

When -N, make sure we don't drop every instruction from
a block, even ones which would otherwise be empty.
Helps keep line numbers around for debugging, particularly
for break and continue statements (which often compile
down to nothing).

Fixes #14379

Change-Id: I33722c4f0dcd502f146fa48af262ba3a477c959a
Reviewed-on: https://go-review.googlesource.com/19854
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
Keith Randall 2016-02-23 10:54:36 -08:00
parent c4cb365ea2
commit e360f7c4db
6 changed files with 20 additions and 12 deletions

View file

@ -202,13 +202,15 @@ func linkpatch(ctxt *Link, sym *LSym) {
p.Pcond = q
}
for p := sym.Text; p != nil; p = p.Link {
p.Mark = 0 /* initialization for follow */
if p.Pcond != nil {
p.Pcond = brloop(ctxt, p.Pcond)
if ctxt.Flag_optimize {
for p := sym.Text; p != nil; p = p.Link {
p.Mark = 0 /* initialization for follow */
if p.Pcond != nil {
if p.To.Type == TYPE_BRANCH {
p.To.Offset = p.Pcond.Pc
p.Pcond = brloop(ctxt, p.Pcond)
if p.Pcond != nil {
if p.To.Type == TYPE_BRANCH {
p.To.Offset = p.Pcond.Pc
}
}
}
}