]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make a better bogus line for empty infinite loops
authorDavid Chase <drchase@google.com>
Mon, 18 Nov 2019 19:14:22 +0000 (14:14 -0500)
committerDavid Chase <drchase@google.com>
Tue, 19 Nov 2019 00:38:53 +0000 (00:38 +0000)
The old recipe for making an infinite loop not be infinite
in the debugger could create an instruction (Prog) with a
line number not tied to any file (index == 0).  This caused
downstream failures in DWARF processing.

So don't do that.  Also adds a test, also adds a check+panic
to ensure that the next time this happens the error is less
mystifying.

Fixes #35652

Change-Id: I04f30bc94fdc4aef20dd9130561303ff84fd945e
Reviewed-on: https://go-review.googlesource.com/c/go/+/207613
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/internal/src/xpos.go
test/fixedbugs/issue35652.go [new file with mode: 0644]

index fa4fd058d72ce50767322a03a2f9848e302abb9a..96fbddb5cd6bce357fec7c255a015e7cda4dba41 100644 (file)
@@ -6041,6 +6041,9 @@ func genssa(f *ssa.Func, pp *Progs) {
                if s.bstart[b.ID] == s.pp.next && len(b.Succs) == 1 && b.Succs[0].Block() == b {
                        p := thearch.Ginsnop(s.pp)
                        p.Pos = p.Pos.WithIsStmt()
+                       if b.Pos == src.NoXPos {
+                               b.Pos = p.Pos // It needs a file, otherwise a no-file non-zero line causes confusion.  See #35652.
+                       }
                        b.Pos = b.Pos.WithBogusLine() // Debuggers are not good about infinite loops, force a change in line number
                }
                // Emit control flow instructions for block
index 54fe64cf8629d56fa451bc5d428972b1d2cde516..23c8346757139a5bdf57726dff91e5c3391329af 100644 (file)
@@ -71,6 +71,10 @@ func (p XPos) WithIsStmt() XPos {
 // gdb chooses not to display the bogus line; delve shows it with a complaint, but the
 // alternative behavior is to hang.
 func (p XPos) WithBogusLine() XPos {
+       if p.index == 0 {
+               // See #35652
+               panic("Assigning a bogus line to XPos with no file will cause mysterious downstream failures.")
+       }
        p.lico = makeBogusLico()
        return p
 }
diff --git a/test/fixedbugs/issue35652.go b/test/fixedbugs/issue35652.go
new file mode 100644 (file)
index 0000000..1ae4069
--- /dev/null
@@ -0,0 +1,15 @@
+// compile
+
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f() {
+       for true {
+               if true {
+                       continue
+               }
+       }
+}