]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: try harder to not use an empty src.XPos for a bogus line
authorDavid Chase <drchase@google.com>
Tue, 19 Nov 2019 18:23:35 +0000 (13:23 -0500)
committerDavid Chase <drchase@google.com>
Fri, 22 Nov 2019 03:06:22 +0000 (03:06 +0000)
The fix for #35652 did not guarantee that it was using a non-empty
src position to replace an empty one.  The new code checks again
and falls back to a more certain position.  (The input in question
compiles to a single empty infinite loop, and none of the actual instructions
had any source position at all.  That is a bug, but given the pathology
of this input, not one worth dealing with this late in the release cycle,
if ever.)

Literally:

00000 (5) TEXT "".f(SB), ABIInternal
00001 (5) PCDATA $0, $-2
00002 (5) PCDATA $1, $-2
00003 (5) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
00004 (5) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
00005 (5) FUNCDATA $2, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
b2
00006 (?) XCHGL AX, AX
b6
00007 (+1048575) JMP 6
00008 (?) END

TODO: Add runtime.InfiniteLoop(), replace infinite loops with a call to
that, and use an eco-friendly runtime.gopark instead.  (This was Cherry's
excellent idea.)

Updates #35652
Fixes #35695

Change-Id: I4b9a841142ee4df0f6b10863cfa0721a7e13b437
Reviewed-on: https://go-review.googlesource.com/c/go/+/207964
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
test/fixedbugs/issue35652.go

index 96fbddb5cd6bce357fec7c255a015e7cda4dba41..bda170ec0eee3e50e514b746ee4e9d0b42e3765a 100644 (file)
@@ -6043,6 +6043,9 @@ func genssa(f *ssa.Func, pp *Progs) {
                        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.
+                               if b.Pos == src.NoXPos {
+                                       b.Pos = pp.Text.Pos // Sometimes p.Pos is empty.  See #35695.
+                               }
                        }
                        b.Pos = b.Pos.WithBogusLine() // Debuggers are not good about infinite loops, force a change in line number
                }
index 1ae40697550400fc85439f127e434257cc52190c..178a84d0f8b4ae559c4ef62810569642c1d8af0a 100644 (file)
@@ -6,10 +6,23 @@
 
 package p
 
-func f() {
+func e() {
        for true {
                if true {
                        continue
                }
        }
 }
+
+func g() {}
+
+func f() {
+       i := 0
+       if true {
+               i++
+       }
+       for true {
+               continue
+               g()
+       }
+}