]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: attempt to preserve statements when prove removes code
authorDavid Chase <drchase@google.com>
Tue, 1 Oct 2019 15:10:22 +0000 (11:10 -0400)
committerDavid Chase <drchase@google.com>
Fri, 4 Oct 2019 20:40:43 +0000 (20:40 +0000)
This was a cause of some statements being lost.

Change-Id: I81c95dcf3df6ed8a03b7578a27f9b21d33b3cf39
Reviewed-on: https://go-review.googlesource.com/c/go/+/198484
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/compile/internal/ssa/prove.go

index efa4453f752a9398bc214b30348b06b1a6c3ab72..4f9a4d53fba14a3a5493d7c2a9e74bb9c5c3ee0b 100644 (file)
@@ -5,6 +5,7 @@
 package ssa
 
 import (
+       "cmd/internal/src"
        "fmt"
        "math"
 )
@@ -1284,18 +1285,22 @@ func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
 }
 
 func removeBranch(b *Block, branch branch) {
+       c := b.Controls[0]
        if b.Func.pass.debug > 0 {
                verb := "Proved"
                if branch == positive {
                        verb = "Disproved"
                }
-               c := b.Controls[0]
                if b.Func.pass.debug > 1 {
                        b.Func.Warnl(b.Pos, "%s %s (%s)", verb, c.Op, c)
                } else {
                        b.Func.Warnl(b.Pos, "%s %s", verb, c.Op)
                }
        }
+       if c != nil && c.Pos.IsStmt() == src.PosIsStmt && c.Pos.SameFileAndLine(b.Pos) {
+               // attempt to preserve statement marker.
+               b.Pos = b.Pos.WithIsStmt()
+       }
        b.Kind = BlockFirst
        b.ResetControls()
        if branch == positive {