]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix liveness for open-coded defer args for infinite loops
authorDan Scales <danscales@google.com>
Fri, 1 Nov 2019 21:04:08 +0000 (14:04 -0700)
committerDan Scales <danscales@google.com>
Tue, 5 Nov 2019 17:19:16 +0000 (17:19 +0000)
commit1b3a1db19fc68591198149540f7b3c99f56691da
treec7829cb7cc4d46c253a346b39cf6910b17815038
parent414c1d454e6d388443239209220fe0783d4dac71
cmd/compile: fix liveness for open-coded defer args for infinite loops

Once defined, a stack slot holding an open-coded defer arg should always be marked
live, since it may be used at any time if there is a panic. These stack slots are
typically kept live naturally by the open-defer code inlined at each return/exit point.
However, we need to do extra work to make sure that they are kept live if a
function has an infinite loop or a panic exit.

For this fix, only in the case of a function that is using open-coded defers, we
compute the set of blocks (most often empty) that cannot reach a return or a
BlockExit (panic) because of an infinite loop. Then, for each block b which
cannot reach a return or BlockExit or is a BlockExit block, we mark each defer arg
slot as live, as long as the definition of the defer arg slot dominates block b.

For this change, had to export (*Func).sdom (-> Sdom) and SparseTree.isAncestorEq
(-> IsAncestorEq)

Updates #35277

Change-Id: I7b53c9bd38ba384a3794386dd0eb94e4cbde4eb1
Reviewed-on: https://go-review.googlesource.com/c/go/+/204802
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
12 files changed:
src/cmd/compile/internal/gc/plive.go
src/cmd/compile/internal/ssa/check.go
src/cmd/compile/internal/ssa/cse.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssa/likelyadjust.go
src/cmd/compile/internal/ssa/loopbce.go
src/cmd/compile/internal/ssa/nilcheck.go
src/cmd/compile/internal/ssa/phiopt.go
src/cmd/compile/internal/ssa/prove.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssa/sparsetree.go
src/runtime/defer_test.go